How to combine numbers and symbols?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
Steven Lord
2019년 10월 28일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!