Programming Previous page   Next Page

Complex Numbers

Complex numbers consist of two separate parts: a real part and an imaginary part. The basic imaginary unit is equal to the square root of -1. This is represented in MATLAB by either of two letters: i or j.

Creating Complex Numbers

The following statement shows one way of creating a complex value in MATLAB. The variable x is assigned a complex number with a real part of 2 and an imaginary part of 3:

Another way to create a complex number is using the complex function. This function combines two numeric inputs into a complex output, making the first input real and the second imaginary:

You can separate a complex number into its real and imaginary parts using the real and imag functions:

Complex Number Functions

See Complex Number Functions for a list of functions most commonly used with MATLAB complex numbers in MATLAB.

Previous page  Floating-Point Numbers Infinity and NaN Next page

© 1994-2005 The MathWorks, Inc.