Accelerating the pace of engineering and science

Documentation Center

• Trial Software

imag

Imaginary part of complex number

imag(z)
imag(A)

Description

imag(z) returns the imaginary part of z.

imag(A) returns the imaginary part of each element of A.

Input Arguments

 z Symbolic number, variable, or expression. A Vector or matrix of symbolic numbers, variables, or expressions.

Examples

Find the imaginary parts of these numbers. Because these numbers are not symbolic objects, you get floating-point results.

`[imag(2 + 3/2*i), imag(sin(5*i)), imag(2*exp(1 + i))]`
```ans =
1.5000   74.2032    4.5747```

Compute the imaginary parts of the numbers converted to symbolic objects:

`[imag(sym(2) + 3/2*i), imag(4/(sym(1) + 3*i)),  imag(sin(sym(5)*i))]`
```ans =
[ 3/2, -6/5, sinh(5)]```

Compute the imaginary part of this symbolic expression:

`imag(sym('2*exp(1 + i)'))`
```ans =
2*exp(1)*sin(1)```

In general, imag cannot extract the entire imaginary parts from symbolic expressions containing variables. However, imag can rewrite and sometimes simplify the input expression:

```syms a x y
imag(a + 2)
imag(x + y*i)```
```ans =
imag(a)

ans =
imag(x) + real(y)```

If you assign numeric values to these variables or if you specify that these variables are real, imag can extract the imaginary part of the expression:

```syms a
a = 5 + 3*i;
imag(a + 2)```
```ans =
3```
```syms x y real
imag(x + y*i)```
```ans =
y```

Clear the assumption that x and y are real:

`syms x y clear`

Find the imaginary parts of the elements of matrix A:

```A = sym('[-1 + i, sinh(x); exp(10 + 7*i), exp(pi*i)]');
imag(A)```
```ans =
[              1, imag(sinh(x))]
[ exp(10)*sin(7),             0]```

Alternatives

You can compute the imaginary part of z via the conjugate: imag(z)= (z - conj(z))/2i.

expand all

Tips

• Calling imag for a number that is not a symbolic object invokes the MATLAB® imag function.