"Conversion to logical from sym is not possible." error shows up when I try to execute the following comands
169 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
X=.25;U=1;
>> eps1=.05;eps2=.05;
>> k=1;
>> while (abs(C-gamma))>=eps1
X=X-inv(Cx)*(C-gamma);
if abs(C-gamma)<eps1
if abs(Lbar_u)<eps2
break;
else
k=k+1;
U=U-K*(Lbar_u);
end
end
end
Conversion to logical from sym is not possible.
I ALSO TRIED TO USE A ALTERNATE WHILE LOOP CONDITION:
while double(subs(abs(C-gamma))) > double(eps1)
BUT THE ERROR PERSISTS
how can i fix it?
2 comentarios
Walter Roberson
el 29 de Mzo. de 2013
Where does the error show up? Which variables are symbols? What is the value of C and gamma and Cx and Lbar_u ?
This appears to be very similar to your previous question, which I do not think is resolved as yet. Are you sure it is not a duplicate ?
upinderjeet
el 30 de Mzo. de 2013
Editada: Walter Roberson
el 30 de Mzo. de 2013
Respuesta aceptada
Walter Roberson
el 30 de Mzo. de 2013
You have
syms L C gamma lambda k K X U
C=(X+U)
because X and U are symbolic at that point, C will be symbolic. You never change the value of C, so it is going to remain symbolic.
You then have the test
while (abs(C-gamma))>=eps1
where gamma and eps1 have numeric values. But C does not have a numeric value, it has a symbolic value, so C-gamma will be symbolic, abs(C-gamma) will be symbolic, and you will be trying to use ">=" to compare a symbolic value to a numeric value.
It appears that up until the beginning of the "while", you want C to be symbolic -- for example it needs to be symbolic in order to use gradient(C,X) . But once you start the while loop, it appears that each time you write C, that you want the symbolic formula for C to be examined, and each place the formula refers to a variable that used to be symbolic but now has a numeric value, you want the numeric value to be substituted for the symbol, giving you a numeric value for C.
If that is what you want, then each place you reference C and want the substitution of numeric values to take place, you need to instead code
double(subs(C))
such as
while (abs(double(subs(C))-gamma))>=eps1
Symbolic formulas are not functions! Once they have symbolic form, any symbolic variables in them are not substituted with numeric values unless you use subs() to tell it to do the substitutions.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Variables, Expressions, Functions, and Preferences en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!