Main Content

abs

Symbolic absolute value (complex modulus or magnitude)

Syntax

Description

abs(z) returns the absolute value (or complex modulus) of z. Because symbolic variables are assumed to be complex by default, abs returns the complex modulus (magnitude) by default. If z is an array, abs acts element-wise on each element of z.

example

Examples

collapse all

[abs(sym(1/2)), abs(sym(0)), abs(sym(pi) - 4)]
ans =
[ 1/2, 0, 4 - pi]

Compute abs(x)^2 and simplify the result. Because symbolic variables are assumed to be complex by default, the result does not simplify to x^2.

syms x
simplify(abs(x)^2)
ans =
abs(x)^2

Assume x is real, and repeat the calculation. Now, the result is simplified to x^2.

assume(x,'real')
simplify(abs(x)^2)
ans =
x^2

Remove assumptions on x for further calculations. For details, see Use Assumptions on Symbolic Variables.

assume(x,'clear')

Compute the absolute values of each element of matrix A.

A = sym([1/2+i  -25;
          i     pi/2]);
abs(A)
ans =
[ 5^(1/2)/2,   25]
[         1, pi/2]

Compute the absolute value of this expression assuming that the value of x is negative.

syms x
assume(x < 0)
abs(5*x^3)
ans =
-5*x^3

For further computations, clear the assumption on x by recreating it using syms:

syms x

Input Arguments

collapse all

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

More About

collapse all

Tips

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

Version History

Introduced before R2006a

See Also

| | | |