Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How can I use the symbolic expression with a logical OR operator...(both being parts of the condition for a while loop)

Asked by upinderjeet on 26 Mar 2013

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 Comments

upinderjeet on 26 Mar 2013

yes....so is there anyhting wrong in doing so......as far as i believe we cudnt use this logical operator for these symbolic expressions....and i beleive that due to the error message I got when I ran the code. "Conversion to logical from sym is not possible"....but I a still new to matlab....so please correct me wheere I am wrong...

Walter Roberson on 26 Mar 2013

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()

upinderjeet on 26 Mar 2013

I got the point you are trying to make here. My next biggest challenge is now to achieve the same goal(i.e execution of all the statements following the while condition, as long as those 2 inequalities in the condition part are hold true). Now, how can I achieve that without using the while loop.

upinderjeet

Products

No products are associated with this question.

0 Answers

Contact us