Documentation

i

Imaginary unit

Description

1i returns the basic imaginary unit. i is equivalent to sqrt(-1).

You can use i to enter complex numbers. You also can use the character j as the imaginary unit. To create a complex number without using i and j, use the complex function.

example

z = a + bi returns a complex numerical constant, z.

example

z = x + 1i*y returns a complex array, z.

Examples

collapse all

Create a complex scalar and use the character, i, without a multiplication sign as a suffix in forming a complex numerical constant.

z = 1+2i
z = 1.0000 + 2.0000i

Create a complex vector from two 4-by-1 vectors of real numbers. z is a 4-by-1 complex vector.

x = [1:4]';
y = [8:-2:2]';

z = x+1i*y
z = 4×1 complex

1.0000 + 8.0000i
2.0000 + 6.0000i
3.0000 + 4.0000i
4.0000 + 2.0000i

Create a complex scalar representing a complex vector with radius, r, and angle from the origin, theta.

r = 4;
theta = pi/4;

z = r*exp(1i*theta)
z = 2.8284 + 2.8284i

Input Arguments

collapse all

Real component of a complex scalar, specified as a scalar.

Data Types: single | double

Imaginary component of a complex scalar, specified as a scalar.

If b is double, you can use the character, i, without a multiplication sign as a suffix in forming the complex numerical constant.

Example: 7i

If b is single, you must use a multiplication sign when forming the complex numerical constant.

Example: single(7)*i

Data Types: single | double

Real component of a complex array, specified as a scalar, vector, matrix, or multidimensional array.

The size of x must match the size of y, unless one is a scalar. If either x or y is a scalar, MATLAB® expands the scalar to match the size of the other input.

single can combine with double.

Data Types: single | double

Imaginary component of a complex array, specified as a scalar, vector, matrix, or multidimensional array.

The size of x must match the size of y, unless one is a scalar. If either x or y is a scalar, MATLAB expands the scalar to match the size of the other input.

single can combine with double.

Data Types: single | double

Output Arguments

collapse all

Complex array, returned as a scalar, vector, matrix, or multidimensional array.

The size of z is the same as the input arguments.

z is single if at least one input argument is single. Otherwise, z is double.

Tips

• For speed and improved robustness in complex arithmetic, use 1i and 1j instead of i and j.

• Since i is a function, it can be overridden and used as a variable. However, it is best to avoid using i and j for variable names if you intend to use them in complex arithmetic.

• Use the complex function to create a complex output in the following cases:

• When the names i and j might be used for other variables (and do not equal sqrt(-1))

• When the inputs are not double or single

• When the imaginary component is all zeros