Why does the ABS function on symbolic variables not give the real and imaginary parts separately in the Symbolic Math Toolbox 5.5 (R2010b)?
4 views (last 30 days)
Show older comments
MathWorks Support Team
on 13 Apr 2012
Commented: Paul
on 30 May 2021
Following is the reproduction code:
syms x y real
syms z complex
z=x+i*y;
abs(z);
This returns abs(x + y*i), instead of (x^2 + y^2)^(1/2).
Accepted Answer
MathWorks Support Team
on 13 Apr 2012
The ability to do so has been incorporated in Release 2012a (R2012a) using the REWRITE function which was introduced in this release. The following code gives the desired result:
syms x y real
z = x + i*y;
a = abs(z);
rewrite(a,'sqrt')
For previous product releases, read below for possible workarounds:
The ability to separate real and imaginary parts separately using ABS is not available in the Symbolic Math Toolbox.
As a workaround, you could use the MuPAD function RECTFORM as follows:
syms x y real;
z = x + i*y;
feval(symengine, 'rectform', abs(z))
Note that MuPAD assumes variables to be complex if not declared to
be real. Hence the need to use the REAL keyword.
Another possible workaround is as follows:
SIMPLIFY can be used to get the desired result. The example code is as follows:
syms x y real
z = x + i*y;
abs(z)
simplify(abs(z))
1 Comment
Paul
on 30 May 2021
Can you post some code showing your concern? Is the following not what you expect?
syms x y real
z = 1/(x + 1i*y);
rewrite(abs(z),'sqrt')
More Answers (0)
See Also
Categories
Find more on Special Values in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!