Effacer les filtres
Effacer les filtres

symbolic logical operation can't get right answer

2 vues (au cours des 30 derniers jours)
alice W
alice W le 5 Juil 2019
Commenté : alice W le 5 Juil 2019
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Juil 2019
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 commentaires
Walter Roberson
Walter Roberson le 5 Juil 2019
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.
alice W
alice W le 5 Juil 2019
I got that. Many thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by