How do I constrain symbolic functions to the real numbers in MATLAB R2025a Symbolic Math Toolbox?

8 views (last 30 days)
This question was flagged by Walter Roberson

I am computing pinv() on functions of time, and the inverse outputs complex values in the form of "conj(expr)". However, I know the function should be real, and I want to constrain the function to the real values.
According to the "assume" function documentation, only symbolic variables and expressions can be assumed real. Syntax such as:

>> syms x1(t) x2(t) real
and 

>> syms x1(t) x2(t)

>> assume(x1, 'real'); assumeAlso(x2, 'real')
are not supported. See the error:

"Error using symfun/assume (line 12) Assumptions on symbolic functions not supported. Make assumptions on symbolic variables and expressions instead."
What is the best way to assume my functions are real so that I do not get complex results after computation?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Sep 2025 at 0:00
Currently, symbolic function 'symfun' objects are not supported under the assumption workflow.
As a workaround, you can assume the 'sym' object expressions (x1(t), x2(t)) within the symfun objects are real:
>> syms x1(t) x2(t)
>> assume(x1(t), 'real'); assumeAlso(x2(t), 'real')
You can also extract the real part of the output with the "real" function:
>> syms x1(t)
>> A = [1; x1];
>> Ap = real(pinv(A))
>> Ap = simplify(Ap)
Ap(t) =
[1/(imag(x1(t))^2 + real(x1(t))^2 + 1), (abs(x1(t))^2*real(1/x1(t)))/(abs(x1(t))^2 + 1)]
The output will still contain "real" calls, but simplifying with the "simplify" method will reduce the "real(conj())" components.
The functionality of making mathematic assumptions on the 'symfun' object has been submitted to our developers so that they may consider adding it in a future release of MATLAB.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!