Matlab simplify boolean expression
Afficher commentaires plus anciens
I want to simplify a boolean algebra expression. I have taken this example from matlab online help but it does not work:
simplify((a and b) or (a and (not b)), logic)
Any suggestion?
I am using matlab R2012a (7.14.0.739)
Réponses (3)
Geoff
le 27 Mai 2012
The expression:
(A && B) || (A && ~B)
Is logically equivalent to:
A
The reason is that both terms require A to be true, and the whole expression evaluates to true regardless of whether B is true or false. If you drew up a truth table for this, it'd be immediately obvious.
[EDIT] Hadn't clicked that the poster was talking about the symbolic math toolbox.
syms a,b;
simplify( (a & b) | (a & ~b) )
3 commentaires
Oleg Komarov
le 28 Mai 2012
I confirm that the code in the comment works.
Please post it here so that the OP can accept your answer.
Geoff
le 28 Mai 2012
Cheers.. I should stop answering outside my area of experience. =)
Oleg Komarov
le 28 Mai 2012
But that's how you learn new things!
Alexander
le 29 Mai 2012
You have copied a MuPAD command. Did you use it inside a MuPAD Notebook? If not, type this at the MATLAB command prompt:
mupad
This will open a MuPAD Notebook. There, paste the input near the bracket (red text should appear) and press enter:
[ simplify((a and b) or (a and (not b)), logic)
a
If you don't want to open a MuPAD notebook, try this in MATLAB:
evalin(symengine, 'simplify((a and b) or (a and (not b)), logic)')
Though if you prefer to stay in MATLAB, you should take what Geoff suggests:
syms a b;
simplify((a & b) | (a & ~b))
(For some reason it did not work for me with the comma between a and b).
Catégories
En savoir plus sur Utilities for the Solver dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!