Symbolic boolean function error at evaluation

6 visualizaciones (últimos 30 días)
timo
timo el 20 de Mzo. de 2017
Comentada: John Smith el 23 de Abr. de 2018
clear all
syms x b a
x(a,b) =xor(a,b)
y(a,b) = and(or(a,b),(not(and(a,b))))
x(0,0)
y(0,0)
I get an error at y(0,0). Can someone help ?
Error using symengine
The operand is invalid.
Error in sym/subs>mupadsubs (line 150)
G = mupadmex('symobj::fullsubs',F.s,X2,Y2);
Error in sym/subs (line 135)
G = mupadsubs(F,X,Y);
Error in symfun/feval>evalScalarFun (line 42)
y = subs(formula(Ffun), Fvars, inds);
Error in symfun/feval (line 28)
varargout{1} = evalScalarFun(F, Fvars, varargin);
Error in symfun/subsref (line 175)
B = feval(A,inds{:});

Respuestas (2)

Renee Coetsee
Renee Coetsee el 27 de Mzo. de 2017
I was able to isolate the error at y(0,0) to the "or(a,b)" function in "y(a,b)". You are getting this error because you need to use logical operators (and, or, ~, |, &, ...) with symbolic expressions and variables. Always make sure that you use logical expressions, such as:
y(a,b) = or(a~=0, b~=0);
"x(0,0) does not cause an error because "xor" in the Symbolic engine works not only on logical values, but also accepts numbers. This does not match other the other functions, so you should try to always use logical expressions.
  1 comentario
John Smith
John Smith el 23 de Abr. de 2018

This gives something unexpected:

>> subfn(x1,x2) = or(x1~=0, x2~=0); subfn(1,0)
ans =
0 ~= 0 | 1 ~= 0

And while it still converges to the correct value:

>> subfn(x1,x2) = or(x1~=0, x2~=0); simplify(subfn(1,0))
ans =
TRUE

I suppose it's not the best way of doing this.

Iniciar sesión para comentar.


John Smith
John Smith el 23 de Abr. de 2018
Symbolic Toolbox has some own weird boolean constants: TRUE and FALSE. I couldn't yet find the less tricky way of obtaining them than this:
TRUE = sym(1) | 1;
FALSE = sym(0) & 0;
Then if you do:
>> subfn(x1,x2) = or(x1, x2); subfn(1,0)
Error using symengine (line 59)
The operand is invalid.
But:
>> subfn(x1,x2) = or(x1, x2); subfn(FALSE,TRUE)
ans =
TRUE

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by