Borrar filtros
Borrar filtros

Bisection method, Numerical analysis

1 visualización (últimos 30 días)
yonatan friedman
yonatan friedman el 6 de Nov. de 2020
Editada: Matt J el 6 de Nov. de 2020
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?

Respuesta aceptada

Matt J
Matt J el 6 de Nov. de 2020
Editada: Matt J el 6 de Nov. de 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]);
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.

Más respuestas (0)

Categorías

Más información sobre Embedded Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by