How can I use the symbolic expression with a logical OR operator...(both being parts of the condition for a while loop)
1 次查看(过去 30 天)
显示 更早的评论
I am trying to create a while loop as follows:
while (abs(C(X,U)-gamma)>=eps1)||(abs(Lbar_u(X,U)))
if abs(Lbar_u(X,U))>=eps2
k=k+1;
U=U-K*Lbar_u(X,U);
if abs(C(X,U)-gamma)>=eps1
X=X-inv(Cx(X,U))*(C(X,U)-gamma)
end
end
elseif abs(C(X,U)-gamma)>=eps1
X=X-inv(Cx(X,U))*(C(X,U)-gamma)
end
end
THE ERROR MESSAGE WHICH I GET IS AS FOLLOWS:
"Conversion to logical from sym is not possible"
what can I do??
11 个评论
Walter Roberson
2013-3-26
There are circumstances under which it makes sense to use logical operators with symbolic expressions, but a "while" condition is not suitable.
In some cases what would be suitable would be constructing a piecewise expression. I do not think your while loop is suitable for that, though.
If you had actual values to work with for X and U and eps1 and eps2, then you could use subs() to create symbolic numeric values that could be compared, something like
double(subs(abs(C(X,U)-gamma))) > double(eps1)
though usually there are more efficient ways to code, such as using matlabFunction()
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!