i - Imaginary unit - MATLAB (original) (raw)
Syntax
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.
[z](#bt4ql29-1-z) = [a](#bt4ql29-1-a) + [b](#bt4ql29-1-b)i
returns a complex numerical constant, z
.
[z](#bt4ql29-1-z) = [x](#bt4ql29-1-x) + 1i*[y](#bt4ql29-1-y)
returns a complex array, z
.
Examples
Create a complex scalar and use the character, i
, without a multiplication sign as a suffix in forming a complex numerical constant.
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 = rexp(1itheta)
Input Arguments
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
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
and1j
instead ofi
andj
. - Since
i
is a function, it can be overridden and used as a variable. However, it is best to avoid usingi
andj
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
andj
might be used for other variables (and do not equalsqrt(-1)
) - When the inputs are not
double
orsingle
- When the imaginary component is all zeros
- When the names
Extended Capabilities
Version History
Introduced before R2006a