what is this eror and what does it mean and how can i solve it ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
clear all
x=1 :0.1:10;
f=inline('x-exp(sin(x))');
plot(x.f(x)).grid;
a=1;fa=f(a);
h=10;fb=f(b);
i=0:Nmax-20;c
eps=1.0e-3;
if((fa*fb)<0)
for i=0 :nmax
x=(a+b)/2;
i=i+1;
it says here that ('loop index 'i' is changed inside of a FOR loop)
if(sign(f(x))==sign(fa));
a=x;fa=f(x);
else
b=x; fb=f(x);
end
fprintf('le nombrre d''iteration i=%d\n',i)
fprintf('l"intervalle [a,b]=[%f,%f]\n',a,b)
fprintf('l"intervalle [f(a),f(b)]=[%f,%f]\n',f(a),f(b))
fprintf('la solution approchée x=%f\n',x)
plot(x,f(x),'r+');
end
else disp(ggg)
end
2 comentarios
Matt J
el 14 de Mayo de 2022
What is this intended to do?
plot(x.f(x)).grid;
It is not close to any Matlab syntax that I have seen.
Respuestas (1)
Jan
el 14 de Mayo de 2022
it says here that ('loop index 'i' is changed inside of a FOR loop)
Yes, and this is the clear explanation already. Do not change the loop counter inside the loop explicitly. This is causing confusions only. Simply omuit the line "i=i+1;"
Avoid the cargo cult programming of "clear all". This is not useful, but removes all loaded functions from the RAM. Reloading them from the slow disk is a waste of time and energy.
Redefining important Matlab functions as variablöes cause unexpected behavior frequently. Here it is "eps". It is a good programming practice, to avoid this.
Inline expressions are outdated for 20 years now. Prefer anonymous functions:
% f=inline('x-exp(sin(x))');
f = @(x) x-exp(sin(x));
Fix this (as Matt J has mentioned already:
plot(x.f(x)).grid;
0 comentarios
Ver también
Categorías
Más información sobre Environment and Settings 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!