Need help with my bisection code
Mostrar comentarios más antiguos
Basically, I use Newton-Raphson method to find roots but if this one fails, my program calls bisection method which is not working. Something is wrong and I can't seem to figure it out. I need to use bisection method to find the roots and my output will be x3, nrfail. The interval is from 0 to 100. If someone could please help. I think I am missing naming the variables and there is an error before the break.
function [ x3, nrfail ] = bisection( fun,x1,y1,x2,y2,tol )
check=1;
dyold=1e12;
nrfail=0;
tol=1e-12;
while check > tol
x3=(x1+x2)/2;
y3=feval(fun,x3);
if y1*y3 < 0
x2=x3;
y2=y3;
else
x1=x3;
y1=y3;
end % ERROR
dy=abs(yl-yr);
if dy>dyold
nrfail=1;
break
end
check= abs(1-x1/x3);
end
end
Respuesta aceptada
Más respuestas (1)
Nahid Hasan
el 2 de Feb. de 2022
0 votos
Write the MATLAB code for finding out the root of this equation using Newton
Raphson method:
x3-x+1 = 0.
Categorías
Más información sobre Newton-Raphson Method en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!