Simplifying symbolic expression to get real of real function in it.

32 views (last 30 days)
I m having a complicated symbolic expression which consists of real function with a complex symbolic expression as an argument to it. I want to simplify this complicated symbolic expression so that i get an expression which does not have real function in it.
How do i do it?

Answers (1)

Walter Roberson
Walter Roberson on 28 Dec 2024 at 21:29
syms x
(x^3 + x)/x^2 + 5
ans = 
real(ans)
ans = 
You can see that if you have a real() call then the Symbolic Toolbox already automatically picks out the portions that are certain to be real and moves them outside the real() call.
If you have a real() call that is not simplifying the expression, then either the expression contains calls to unknown functions
syms F(x)
real(F(x) + 5)
ans = 
or else the expression is in complex variables.
When you syms a variable, by default the variable is assumed to be complex, unless you add the real flag to the syms call
syms x real
or else you use assume or assumeAlso to explicitly mark the variable as real, or to add an assertion that implies the variable is real
syms y
assume(y > 0)
real(y + 5)
ans = 
Here, the assumption of >0 can only be satisfied if y is real, so you get y is real "for free"

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!