How to combine numbers and symbols?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ivan
am 28 Okt. 2019
Beantwortet: Steven Lord
am 28 Okt. 2019
While calculation some complex expressions with symbols and numbers, Matlab appears to be a weak tool to extract later Real and Imag part...
I have an easy question..
Let's assume we have an expression
syms a real
and I want to calculate - 4*a
how "4" will be treated here? and "4*a"
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 28 Okt. 2019
If you state when you define the symbolic variable a that it is real, Symbolic Math Toolbox can take advantage of that information.
>> syms a real
>> real(4*a)
ans =
4*a
>> imag(4*a)
ans =
0
Note that even though you've said a is real, the result of operating on a may have a non-zero imaginary part under certain circumstances.
>> real(sqrt(a))
ans =
real(a^(1/2))
>> imag(sqrt(a))
ans =
imag(a^(1/2))
Consider substituting a = 4 into sqrt(a). The result of that calculation has zero as its imaginary part. But if you substitute a = -1, that has a non-zero imaginary part.
>> imag(subs(sqrt(a), a, 4))
ans =
0
>> imag(subs(sqrt(a), a, -1))
ans =
1
If you were to tell Symbolic Math Toolbox that not only is a real but it is also positive, the toolbox can take into account that information.
>> syms b positive
>> imag(sqrt(b))
ans =
0
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!