Documentation Center

  • Trial Software
  • Product Updates

real

Real part of complex number

Syntax

real(z)
real(A)

Description

real(z) returns the real part of z.

real(A) returns the real 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 real parts of these numbers. Because these numbers are not symbolic objects, you get floating-point results.

[real(2 + 3/2*i), real(sin(5*i)), real(2*exp(1 + i))]
ans =
    2.0000         0    2.9374
 

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

[real(sym(2) + 3/2*i), real(4/(sym(1) + 3*i)),  real(sin(sym(5)*i))]
ans =
[ 2, 2/5, 0]

Compute the real part of this symbolic expression:

real(sym('2*exp(1 + i)'))
ans =
2*cos(1)*exp(1)
 

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

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

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

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

Clear the assumption that x and y are real:

syms x y clear
 

Find the real parts of the elements of matrix A:

A = sym('[-1 + i, sinh(x); exp(10 + 7*i), exp(pi*i)]');
real(A)
ans =
[             -1, real(sinh(x))]
[ cos(7)*exp(10),            -1]

Alternatives

You can compute the real part of z via the conjugate: real(z)= (z + conj(z))/2.

More About

expand all

Tips

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

See Also

|

Was this topic helpful?