Bisection method, Numerical analysis
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
y=@(x) ((x+1)^2)*(exp(x^2-2)-1);
a=0; b=1;
m=(a+b)/2;
while abs(y(m))<0.01
disp(m)
if y(a)*y(m)<0
b=m;
elseif y(b)*y(m)<0
a=m;
end
end
~~~~~
i want to find m<0.01?
what am i doing wrong?
0 commentaires
Réponse acceptée
Matt J
le 6 Nov 2020
Modifié(e) : Matt J
le 6 Nov 2020
a=0; b=1;
m=(a+b)/2;
while abs(y(m))>0.01
if y(a)*y(m)<0
b=m;
elseif y(b)*y(m)<0
a=m;
end
m=(a+b)/2;
[m,abs(y(m))]
end
Aside from that, however, your function does not have a root in the interval [0,1], as can be seen from the following:
fplot( @(x) ((x+1)^2)*(exp(x^2-2)-1) ,[0,1]);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Embedded 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!