Symbolic absolute value (complex modulus or magnitude)
[abs(sym(1/2)), abs(sym(0)), abs(sym(pi) - 4)]
ans = [ 1/2, 0, 4 - pi]
abs(x)^2 and simplify the result. Because
symbolic variables are assumed to be complex by default, the result does not simplify to
syms x simplify(abs(x)^2)
ans = abs(x)^2
x is real, and repeat the calculation. Now, the result is
ans = x^2
Remove assumptions on
x for further calculations. For details,
see Use Assumptions on Symbolic Variables.
Compute the absolute values of each element of matrix
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
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
Input, specified as a number, vector, matrix, or array, or a symbolic number, vector, matrix, or array, variable, function, or expression.
The absolute value of a complex number z = x + y*i is the value . Here, x and y are real numbers. The absolute value of a complex number is also called a complex modulus.
abs for a number that is not a symbolic object invokes the