Imaginary unit
collapse all in page
Syntax
1i
z = a + bi
z = x +1i*y
Description
1i
returns the basic imaginary unit. i
isequivalent to sqrt(-1)
.
You can use i
to enter complex numbers.You also can use the character j
as the imaginaryunit. To create a complex number without using i
and j
,use the complex function.
z = a + bi
returnsa complex numerical constant, z
.
example
z = x +1i*y
returns a complex array, z
.
example
Examples
collapse all
Complex Scalar
Open Live Script
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
Complex Vector
Open Live Script
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
Complex Exponential
Open Live Script
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
a
— Real component of complex scalar
scalar
Real component of a complex scalar, specified as a scalar.
Data Types: single
| double
b
— Imaginary component of complex scalar
scalar
Imaginary component of a complex scalar, specified as a scalar.
If b
is double
, you canuse the character, i
, without a multiplicationsign as a suffix in forming the complex numerical constant.
Example: 7i
If b
is single
, you mustuse a multiplication sign when forming the complex numerical constant.
Example: single(7)*i
Data Types: single
| double
x
— Real component of complex array
scalar | vector | matrix | multidimensional array
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
isa scalar, MATLAB® expands the scalar to match the size of theother input.
single
can combine with double
.
Data Types: single
| double
y
— Imaginary component of complex array
scalar | vector | matrix | multidimensional array
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
isa scalar, MATLAB expands the scalar to match the size of theother input.
single
can combine with double
.
Data Types: single
| double
Output Arguments
collapse all
z
— Complex array
scalar | vector | matrix | multidimensional array
Complex array, returned as a scalar, vector, matrix, or multidimensionalarray.
The size of z
is the same as the input arguments.
z
is single
if at leastone 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 canbe overridden and used as a variable. However, it is best to avoidusingi
andj
for variable namesif you intend to use them in complex arithmetic.Use the
complex
function to createa complex output in the following cases:When the names
i
andj
mightbe used for other variables (and do not equalsqrt(-1)
)When the inputs are not
double
orsingle
When the imaginary component is all zeros
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006a
See Also
conj | complex | imag | j | real
Topics
- Create Complex Numbers
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office