# imag

Imaginary part of complex number

## Syntax

``imag(z)``

## Description

example

````imag(z)` returns the imaginary part of `z`. If `z` is a matrix, `imag` acts elementwise on `z`.```

## Examples

### Compute Imaginary Part of Numeric Inputs

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 Imaginary Part of Symbolic Inputs

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(2*exp(1 + sym(i)))`
```ans = 2*exp(1)*sin(1)```

### Compute Imaginary Part of Symbolic Expressions

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 by recreating them using `syms`:

`syms x y`

### Compute Imaginary Part for Matrix Input

Find the imaginary parts of the elements of matrix `A`:

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

## Input Arguments

collapse all

Input, specified as a number, vector, matrix, or array, or a symbolic number, variable, array, function, or expression.

## Tips

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

## Alternatives

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