Main Content

imag

Imaginary part of complex number

Syntax

Description

example

imag(z)returns the imaginary part ofz. Ifzis a matrix,imagacts elementwise onz.

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)

计算符号表达式的虚部

In general,imagcannot extract the entire imaginary parts from symbolic expressions containing variables. However,imagcan 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,imagcan 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 thatxandyare real by recreating them usingsyms:

syms x y

Compute Imaginary Part for Matrix Input

Find the imaginary parts of the elements of matrixA:

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

上校lapse all

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

Tips

  • Callingimagfor a number that is not a symbolic object invokes the MATLAB®imagfunction.

Alternatives

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

Version History

Introduced before R2006a

See Also

||||