Imaginary unit
collapse all in page
Syntax
1j
z = a + bj
z = x +1j*y
Description
1j
returns the basic imaginary unit. j
isequivalent to sqrt(-1)
.
You can use j
to enter complex numbers.You also can use the character i
as the imaginaryunit. To create a complex number without using i
and j
,use the complex function.
z = a + bj
returnsa complex numerical constant, z
.
example
z = x +1j*y
returns a complex array, z
.
example
Examples
collapse all
Complex Scalar
Open Live Script
Create a complex scalar and use the character, j
, without a multiplication sign as a suffix in forming a complex numerical constant.
z = 1+2j
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+1j*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(1j*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, j
, without a multiplicationsign as a suffix in forming the complex numerical constant.
Example: 7j
If b
is single
, you mustuse a multiplication sign when forming the complex numerical constant.
Example: single(7)*j
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
j
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 | i | 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