symbolic logical operation can't get right answer
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I have
syms a b c
aa=(a==b)+c
bb=eval(subs(aa,[a,b,c], [1/5, 0, 1051/10000]))
My expected result is
aa=(a==b)+c
bb=
0.1051
However, the actual result is
aa =
a + c == b + c
bb =
logical
0
In my opinion, (a==b) should be computed first. The logical result then is added to c. Finally I can get a double number 0.1051. However, the actual result is not what I want.
How did that happen? What can I do to solve this problem?
0 件のコメント
採用された回答
Walter Roberson
2019 年 7 月 5 日
The comparison operators do not return 0 or 1 for the symbolic toolbox: they return constants TRUE or FALSE from DOM::Logical if I recall correctly.
If you want the relational operators to return 0 or 1 then you need to use piecewise(Condition, 1, 0)
Also, using eval() with symbolic expressions has undefined results.
MATLAB has three different programming languages. One is ordinary MATLAB. One is the MuPad engine language. The third is symbolic expressions, which are a hybrid between the other two and have incompatibilities with both of them. eval() applied to a symbolic expression will produce results that are not either MATLAB or MuPad in some situations.
3 件のコメント
Walter Roberson
2019 年 7 月 5 日
Why not? You have an equation and you add c to both sides of it. It is a common algebraic operation when solving equations, adding something to both sides of the equation, or multiplying or dividing both sides of the equation by a value.
Remember, (a==b) in symbolic toolbox is not going to give you a logical value.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!