j - Imaginary unit - MATLAB (2024)

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

aReal component of complex scalar
scalar

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

Data Types: single | double

bImaginary 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

xReal 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

yImaginary 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 and 1j instead of i and j.

  • Since j is a function, it canbe overridden and used as a variable. However, it is best to avoidusing i and j 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 and j mightbe 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

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™.

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.

j - Imaginary unit - MATLAB (1)

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)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

j - Imaginary unit - MATLAB (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Duane Harber

Last Updated:

Views: 5886

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.