Newton raphson using a recursive function
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi everyone,
Does anybody knows how to solve an equation with the Newton Raphson using a recursive function. In other words how do I make this code recursive. Thanks in advance .
clear;
P=5;
x1=P;
iflag=0;
maxiter=40;
E=0.00001;
e=1.0;
%
j=0;
while (e > E )
func=x1^4-P;
Dfunc=4*x1^3;
x2=x1-(func/Dfunc);
e=abs((x2-x1)/x1);
xx=[x1,x1,x2]; yy=[0,func,0];
plot(xx,yy,'b-sq');
hold on;
j=j+1;
x1=x2;
%
if (j>maxiter)
iflag=1;
fprintf('Vous avez atteint le nombre maximal d''itérations\n')
break
end
end
if (iflag==0)
xsol=x2;
fprintf('la solution avec %3d itérations est x=%5.2f \n',j,xsol);
end
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!