need check for Bisection Method

1 vue (au cours des 30 derniers jours)
pepper
pepper le 30 Sep 2020
Commenté : pepper le 30 Sep 2020
%bisection_method
f='func31'
Nmax=100;
tol=0.000001;
a=-10
b=10
if feval(f,a)*feval(f,b)>0
disp('no sol')
else
a0=a; b0=b;
for n=1:Nmax
p=(a+b)/2
if (b-p)/(b0-a0)<tol <------------------------------------------------------------is this right?? b-p? not a b-a?
break
else
if feval(f,a)*feval(f,p)<=0
a=a;
b=p;
else
a=p
b=b
end
end
end
================================
made an expression from relative error
i wrote it down at the class
but there are difference with books
is it
b-p or b-a?

Réponse acceptée

Alan Stevens
Alan Stevens le 30 Sep 2020
When you are close to the solution it won't much matter if you use b-p or b-a. However, you shoud probably use
abs((b-p)/(b0-a0))<tol
  1 commentaire
pepper
pepper le 30 Sep 2020
thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by