what is this eror and what does it mean and how can i solve it ?

1 visualizzazione (ultimi 30 giorni)
clear all
x=1 :0.1:10;
f=inline('x-exp(sin(x))');
plot(x.f(x)).grid;
Dot indexing is not supported for variables of this type.
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

Risposte (1)

Jan
Jan il 14 Mag 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;

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Tag

Prodotti


Release

R2009b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by