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

1 Ansicht (letzte 30 Tage)
khalil chelihi
khalil chelihi am 14 Mai 2022
Kommentiert: Walter Roberson am 14 Mai 2022
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
  2 Kommentare
Matt J
Matt J am 14 Mai 2022
What is this intended to do?
plot(x.f(x)).grid;
It is not close to any Matlab syntax that I have seen.
Walter Roberson
Walter Roberson am 14 Mai 2022
plot(x.f(x)).grid;
looks like Python code.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 14 Mai 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;

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by