How to compute Newton Raphson coding on Matlab?
Afficher commentaires plus anciens
I tried to compute Newton Raphson Algorithm on Matlab to calculate the root estimate for y but the final answer x pop is same as the initial guess which i think is wrong. I don't know where the mistake is in my script. Is there anything missing in my script?
if true
% code
end
x=0.00462; % initial guess
emax=0.0000001; % maximum error (accuracy)
imax=10000; % maximum iteration
dmin=0.000001; % minimum slope
deltax=inf; % approximate error
i=1; % step number
while (i<imax) && (deltax>=emax);
y = x.^5-16.5*x.^4+102.85*x.^3-299.475*x.^2+401.1634*x-194.0612;
y1 = 5*x.^4-66*x.^3+308.55*x.^2-598.95*x+401.1634;
x1=x-(y/y1);
deltax = abs((x1-x)/x1);
if abs(y1)<=dmin;
disp('Too small slope');
break;
end
i=i+1;
x1=x;
end
disp(x)
1 commentaire
Jim Riggs
le 9 Mar 2018
The first thing missing from your script is comments. I suggest that you add comments which describe what each line is doing. Then see if that makes sense.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Newton-Raphson Method dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
