Error: "Conversion from logical to sym is not possible"
Mostrar comentarios más antiguos
I keep getting that error and I am not sure what I am supposed to do to fix it, can someone lead me in the right direction?
alpha=40*pi/180;
func=5/3*cos(alpha)-5/2*cos(phi)+11/6-cos(alpha-phi);
dfunc=diff(func);
xr=30*pi/180;
es=0.000001;
maxit=50;
iter=0;
while (1)
xrold=xr;
xr=xr-func(xr)/dfunc(xr);
iter=iter+1;
if xr~=0, ea=abs((xr-xrold)/xr)*100; end
if ea <= es || iter>=maxit, break, end
end
Warning: Integer operands are required for colon operator when used as index.
Warning: Integer operands are required for colon operator when used as index.
Conversion to logical from sym is not possible.
root=xr
5 comentarios
KALYAN ACHARJYA
el 30 de Nov. de 2019
Please share the code in text (cody) format, not screenshot.
Maia Paige de Beauchamp
el 30 de Nov. de 2019
KALYAN ACHARJYA
el 30 de Nov. de 2019
Editada: KALYAN ACHARJYA
el 30 de Nov. de 2019
phi?
What you are trying do here?
xr=xr-func(xr)/dfunc(xr);
Please note that xr and func are scalar (single values) here.
Maia Paige de Beauchamp
el 30 de Nov. de 2019
KALYAN ACHARJYA
el 30 de Nov. de 2019
Editada: KALYAN ACHARJYA
el 30 de Nov. de 2019
func(xr)>> Represents array indexing in Matlab, if say example
func=[2 3 6 10] and xr=2
then func(xr)>> represents >> func(2)=3 OK in Matlab
But
if xr=0.2 or any decimal number/ negative/zero which is not allowed
func(xr) % Not Allowed
Respuestas (1)
Dhananjay Kumar
el 3 de Dic. de 2019
0 votos
I am assuing that you have declared phi as a symbolic variable by writing
>> syms phi
So func and dfunc are symbolic expressions.
If you want to evaluate the func at a particular phi ( here phi = xr = 30*pi/180), you should use the subs function like:
xr = xr-subs(func,phi,xr)/subs(dfunc,phi,xr);
You are getting first and second warning because of this wrong syntax only.
About the error "Conversion to logical from sym is not possible." :
The expression "ea <= es" (in if statement) just a symbolic expression not a constant value, that's why you are getting this error.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!