What you're trying to do with the while
expression is equivalent to logical(f)
, where f
is a symbolic function (rather than a symbolic value). logical(sym('exp(1)') > 0)
is fine, but logical(sym('exp(f)') > 0)
is generally not going to be (see assume
). Matlab has no way of casting a symbolic variable to a logical (true and false) one. It tries to do this because the short circuit AND
operator, &&
, isn't supported for symbolic variables. For example
a = 1.5;
syms x;
% All of these will not generate errors
y1 = x > 1;
y2 = x > 1 & x < 2;
y3 = x > 1 & x < 2;
y4 = x > 1 & a < 2;
y5 = x > 1 & a > 2;
% These will result in errors
y2 = x > 1 && x < 2;
y3 = x > 1 && x < 2;
y4 = x > 1 && a < 2;
y5 = x > 1 && a > 2;
You should print out subst
and make sure that it is a symbolic value or a function that does not include any variables (if argnames(subst)
returns an empty symbolic matrix then you should be okay). The fact that you get the second error when you call double
seems to imply that subst
is actually an expression that still includes unknown variables. If this is the case, then you'll either need to substitute in other variables or use assumptions (see here) in order to do logical comparisons as you're doing.