Accelerating the pace of engineering and science

# j

Imaginary unit

## Description

1j returns the basic imaginary unit. j is equivalent to sqrt(-1).

You can use j to enter complex numbers. You also can use the character i as the imaginary unit. To create a complex number without using i and j, use the complex function.

example

z = a + bj returns a complex numerical constant, z.

example

z = x + 1j*y returns a complex array, z.

## Examples

expand all

### Complex Scalar

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

Create a complex vector from two 4-by-1 vectors of real numbers.

```x = [1:4]';
y = [8:-2:2]';

z = x+1j*y```
```z =

1.0000 + 8.0000i
2.0000 + 6.0000i
3.0000 + 4.0000i
4.0000 + 2.0000i
```

z is a 4-by-1 complex vector.

### Complex Exponential

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

expand all

### a — Real component of complex scalarscalar

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

Data Types: single | double

### b — Imaginary component of complex scalarscalar

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

If b is double, you can use the character, j, without a multiplication sign as a suffix in forming the complex numerical constant.

Example: 7j

If b is single, you must use a multiplication sign when forming the complex numerical constant.

Example: single(7)*j

Data Types: single | double

### x — Real component of complex arrayscalar | vector | matrix | multidimensional array

Real component of a complex array, specified as a scalar, vector, matrix, or mulitdimensional 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

### y — Imaginary component of complex arrayscalar | vector | matrix | multidimensional array

Imaginary component of a complex array, specified as a scalar, vector, matrix, or mulitdimensional 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

expand all

### z — Complex arrayscalar | vector | matrix | multidimensional array

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.

## More About

expand all

### Tips

• For speed and improved robustness in complex arithmetic, use 1i and 1j instead of i and j.

• Since j is a function, it can be overridden and used as a variable. However, it is best to avoid using i and j 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 and j might be 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

## See Also

Was this topic helpful?