Need help with my bisection code
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Nahid Hasan
2022년 2월 2일
0 개 추천
Write the MATLAB code for finding out the root of this equation using Newton
Raphson method:
x3-x+1 = 0.
카테고리
도움말 센터 및 File Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!