i - Imaginary unit - MATLAB (2024)

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

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, 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

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

i - 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

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

Author: Arline Emard IV

Last Updated:

Views: 5888

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Arline Emard IV

Birthday: 1996-07-10

Address: 8912 Hintz Shore, West Louie, AZ 69363-0747

Phone: +13454700762376

Job: Administration Technician

Hobby: Paintball, Horseback riding, Cycling, Running, Macrame, Playing musical instruments, Soapmaking

Introduction: My name is Arline Emard IV, I am a cheerful, gorgeous, colorful, joyous, excited, super, inquisitive person who loves writing and wants to share my knowledge and understanding with you.