Questions tagged [complex-numbers]

Questions about complex numbers (numbers in the form of x + y∙i where i² = -1), types to represent them in programming languages, and libraries to manipulate them

The complex numbers extend the real numbers to allow negative numbers to have a square root. Every complex number can be expressed in the form x + y * i where x and y are real numbers and i² = -1; this is called the rectangular form of the number. The rectangular form leads to an interpretation of complex numbers as points on a plane, the same way real numbers are akin to points on a line. If y = 0, the number is a real number; if x = 0, the number is called an imaginary number.

A nonzero complex number has a family of representations in the form r exp(i φ) with r > 0, called the polar representation.

Representation and manipulation in programming languages

Floating point complex numbers

1395 questions
7
votes
4 answers

How to get a complex number as a user input in python?

I'm trying to build a calculator that does basic operations of complex numbers. I'm using code for a calculator I found online and I want to be able to take user input as a complex number. Right now the code uses int(input) to get integers to…
shivajna
  • 71
  • 1
  • 1
  • 2
7
votes
1 answer

How to plot a complex system related to its imaginary parts

I've defined the complex symbolic system : syms x sys(x) = ((10+1.*i.*x))/(20+(5.*i.*x)+((10.*i.*x).^2))+((1.*i.*x).^3); ImaginaryPart = imag(sys) RealPart = real(sys) MATLAB returned the following results: ImaginaryPart(x) = - real(x^3) +…
salam
  • 229
  • 1
  • 4
7
votes
2 answers

F# - How do I extend a type with get_Zero so I can use an existing type generically?

I attempt the following: let c x = System.Numerics.Complex(x, 0.0) let sum = [c 1.0; c 2.0] |> List.sum But I get this error: The type 'System.Numerics.Complex' does not support the operator 'get_Zero' I read the rules on type extensions, from…
Overlord Zurg
  • 3,430
  • 2
  • 22
  • 27
7
votes
3 answers

Complex numbers in Swift?

Does Apple's Swift language support complex numbers out of the box? I couldn't find any mention in the docs any equivalent for C++ std::complex nor could I find one when playing with it.
yairchu
  • 23,680
  • 7
  • 69
  • 109
7
votes
3 answers

Complex number equals method

I'm making a complex number class in Java like this: public class Complex { public final double real, imag; public Complex(double real, double imag) { this.real = real; this.imag = imag; } ... methods for arithmetic…
Boann
  • 48,794
  • 16
  • 117
  • 146
7
votes
1 answer

Is approx() designed to be used with complex numbers?

I did the following experiment, since there's no mention of complex data on the approx help page: Rgames> zfoo [1] 1+ 6i 2+ 7i 3+ 8i 4+ 9i 5+10i Rgames> approx(zfoo,n=10) $x [1] 1.000000 1.444444 1.888889 2.333333 2.777778 3.222222 3.666667…
Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
7
votes
2 answers

Assembly code/AVX instructions for multiplication of complex numbers. (GCC inline assembly)

We're running a scientific program and we would like to implement AVX features. The whole program (written in Fortran+C) is going to be vectorized and at the moment I'm trying to implement complex number multiplication within GCC inline…
Jean Nicolas
  • 73
  • 1
  • 5
7
votes
1 answer

Multiple roots in the complex plane with R

I've been trying to find a function that returns all complex solutions of an equation such as: 16^(1/4) = 2+i0, -2+i0, 0+i2, 0-i2 As it stands, if I enter 16^(1/4) into the console, it only returns 2. I can write a function for this but I was…
N8TRO
  • 3,348
  • 3
  • 22
  • 40
7
votes
4 answers

extract real number from array in matlab

I would like to extract only the real numbers from an array containing imaginary numbers also I would like to eliminate the imaginary numbers from array. Therefore, from an array of 10 elements, of which 5 real, and 5 imaginary, to obtain an array…
carminePat
  • 159
  • 2
  • 5
  • 13
6
votes
0 answers

How to plot an isosurface of a 3D complex field with Mayavi avoiding color interpolation artifacts?

Taking as a basis the Atomic orbital example in the example gallery, I'm trying to visualize a 3D arbitrary complex field using an isosurface, in the way the cyclic HSV colormap illustrates the phase of the field. However, there is a problem in the…
Rafael
  • 402
  • 5
  • 17
6
votes
1 answer

CMPLX Yields Undefined Symbol with GCC

I'm trying to hunt down a problem using complex literals when compiling with GCC. Consider the following #include #include int main(void) { double complex z = CMPLX(0.0, -1.0); printf("z = %.1f%+.1fi\n", creal(z),…
Keith Prussing
  • 803
  • 8
  • 19
6
votes
2 answers

Obtaining coefficients of complex expressions in sympy

I have a relatively simple complex sympy expression which one can easily read the coefficients off of the variables. However coeff function does not appear to be working correctly import sympy as sp a,b = sp.symbols("a, b") expr = 2640.0*a -…
shaun252
  • 61
  • 4
6
votes
1 answer

Fortran sqrt of complex number -1 gives different results

This code print *, sqrt(cmplx(-1)) print *, sqrt(cmplx(-1,0)) print *, sqrt((-1,0)) print *, sqrt(-(1,0)) gives me this output (0.00000000,1.00000000) (0.00000000,1.00000000) (0.00000000,1.00000000) (0.00000000,-1.00000000) I believe that the…
alexis
  • 410
  • 4
  • 18
6
votes
2 answers

Is there a library for large precision complex numbers in Python?

Is there a library for large precision complex numbers in Python?
eddie
  • 170
  • 7
6
votes
5 answers

Change the complex number output format

There is the complex<> template in C++ standard library, and it has an overloaded << operator so that it outputs complex numbers in the (real_part, im_part) format. I need to change the behavior of that operator for complex numbers so that the…
grzkv
  • 2,599
  • 3
  • 26
  • 37