complex-numbers

How should complex numbers be rendered?

Mathematics naive question: What is the "canonical" way to represent 14+1i? 14+i1 or 14+i Similarly, is it likely, in the 'real world', that scientific notation is going to creep into a complex number so as to freak out a complex numbers parser? For example, 1.2345E+02-1.7002E-09i Edit: Finally, is it 8.45358210351126e+066i ...

As a programmer how would you explain imaginary numbers?

As a programmer I think it is my job to be good at math but I am having trouble getting my head round imaginary numbers. I have tried google and wikipedia with no luck so I am hoping a programmer can explain in to me, give me an example of a number squared that is <= 0, some example usage etc... ...

How to calculate log of a complex number to a base other than 'e'?

I have this bit of VB6 sliced out of a project I'm working on: Public Function C_Ln(c As ComplexNumber) As ComplexNumber Set C_Ln = toComplex(Log(C_Abs(c)), Atan2(c.Imag, c.Real)) End Function The VB6 Log() function is base-e. I'd like to cook up versions of this to do base-2, base-10 and base-n. Where do I start? ...

Haskell and Quadratics

Hi, I have to write a program to solve quadratics, returning a complex number result. I've gotten so far, with defining a complex number, declaring it to be part of num, so +,- and * - ing can take place. I've also defined a data type for a quadratic equation, but im now stuck with the actual solving of the quadratic. My math is quite...

Haskell Parsing Error

So I have finished creating my own complex number data type in haskell. I've also, thanks to another question on here, got a function that will solve a quadratic equation. The only problem now is that the code generates a parsing error in hugs, when trying to solve a quadratic with complex roots. i.e. In hugs... Main> solve (Q 1 2 1)...

Overloading operators in C++

See edit at the end I am trying to overload the + operator in C++ to allow me to add two complex numbers. (add the real and add the imaginary). Here is my overloaded function: ComplexNum operator+(ComplexNum x, ComplexNum y){ ComplexNum result; result.real = (x.getReal() + y.getReal()); result.imag = (x.getImag() + y.getImag()); retu...

Complex iterations in haskell

Hi I have this complex iterations program I wrote in TI Basic to perform a basic iteration on a complex number and then give the magnitude of the result: INPUT “SEED?”, C INPUT “ITERATIONS?”, N C→Z For (I,1,N) Z^2 + C → Z DISP Z DISP “MAGNITUDE”, sqrt ((real(Z)^2 + imag(Z)^2)) PAUSE END What I would like to do is make a Haskell versio...

Java math expression parser that can take complex numbers as a variable?

I am writing a program in Processing that transforms complex numbers. However, I want to have a method of taking an input string and calculating the transformation using a complex variable. For example: 1/(z+1) (z^2)/(z/2) where z is a complex number. Now, I've looked at JEP and some examples, but I cannot work out if it would allow y...

Complex number notation

My DotNET application has a limited scripting language build in (modelled loosely on VBScript) mainly for post-processing numbers, points and vectors. I've just added support for complex numbers, but I'm struggling with the notation. I don't want to use the A + Bi notation, since it is not a clear division if A or B are defined as equat...

Complex numbers: fast cartesian to polar conversion

Hi. I'm looking for a fast way to turn an array of complex numbers into polar representation. E.g, given a complex number X I want to turn it into polar representation like this: Q.phase = atan2 (X.imag / X.real); Q.magniude = sqrt (X.imag * X.imag + X.real * X.real); I need to do this conversion around 400 thousand times pe...

Why does this code return 'complex'?

# Example: provide pickling support for complex numbers. try: complex except NameError: pass else: def pickle_complex(c): return complex, (c.real, c.imag) # why return complex here? pickle(complex, pickle_complex, complex) Why? The following code is the pickle function being called: dispatch_table = {} def ...

What's a nice method to factor gaussian integers?

I already have prime factorization (for integers), but now I want to implement it for gaussian integers but how should I do it? thanks! ...

Better use a tuple or numpy array for storing coordinates

Hi, I'm porting an C++ scientific application to python, and as I'm new to python, some problems come to my mind: 1) I'm defining a class that will contain the coordinates (x,y). These values will be accessed several times, but they only will be read after the class instantiation. Is it better to use an tuple or an numpy array, both in...

Encode complex number as RGB pixel and back

How is it better to encode a complex number into RGB pixel and vice versa? Probably (logarithm of) an absolute value goes to brightness and an argument goes to hue. Desaturated pixes should receive randomized argument in reverse transformation. Something like: 0 -> (0,0,0) 1 -> (255,0,0) -1 -> (0,255,255) 0.5 -> (128,0,0) i -> (255,2...

question about complex values in java

We know that the general form of complex numbers is like this: z=a+i*b, where i is sqrt(-1). I have a question about how to express this in Java ? ...

Calculating complex numbers with rational exponents

Yesterday I created this piece of code that could calculate z^n, where z is a complex number and n is any positive integer. --snip-- float real = 0; float imag = 0; // d is the power the number is raised to [(x + yi)^d] for (int n = 0; n <= d; n++) { if (n == 0) { real += pow(a, d); } else { // binomial theorem switch...

splint failing on code that includes complex.h

I'm trying to run splint on a C source that includes complex.h from the standard C library to support complex arithmetic. Unfortunately, splint fails with the following error. Splint 3.1.2 --- 03 May 2009 /usr/include/bits/cmathcalls.h:54:31: Parse Error: Non-function declaration: _Complex : extern double. (For help on...

How to use c++ std complex numbers in QtScript

Hello everyone, I try to find out how to use complex numbers in QtScripts such that slots defined with complex arguments can be called from a QtScript. Also basic algebra (+,-,exp, ... ) of complex-numbers should be accessible to the user from the script. Just for illustration want I want to call is: #include<complex> typedef complex<...

complex number types in mixing C(99) and C++

I'm writing a math library, the core of it is in C++. Later it may be implemented in pure C (C99 I suppose). I think I need a C like API so that I can get Python and matlab and the like to use the library. My impression is that doing this with C++ is painful. So is there a good or standard or proper way to cast between double complex *s...

How to convert a string to complex<float> in C++?

How do I easily convert a string containing two floats separated by a comma into a complex? For instance: string s = "123,5.3";//input complex<float> c(123,5.3);//output/what I need Is there an simpler/faster way than to split the string, read the two values and return thecomplex<float>? ...