How do I constrain symbolic functions to the real numbers in MATLAB R2025a Symbolic Math Toolbox?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 15 Sep 2025
Réponse apportée : MathWorks Support Team
le 24 Sep 2025
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?
Réponse acceptée
MathWorks Support Team
le 1 Oct 2025
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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Variables, Expressions, Functions, and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!