Newton raphson using a recursive function

4 visualizaciones (últimos 30 días)
Patirick Legare
Patirick Legare el 1 de Mzo. de 2019
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

Respuestas (0)

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by