Newton-Raphson Method Error

5 vues (au cours des 30 derniers jours)
mPackEE
mPackEE le 19 Fév 2015
I have created a function to do Newton-Raphson method on a gas law problem. Supposedly, you enter pressure, temperature, and receive the specific volume as a result. Unfortunately, I only seem to be receiving one of my constants as the output. I can't seem to find where I went wrong. Any help?
function result=MyNewtonFn(p,t)
a=0.1747;
b=0.00138;
r=0.29681;
l(1)=1;
function u=fun(x)
u=(p+a./x.^2).*(x-b)/(r*t);
end
function w=der(q)
w= (p + a./q.^2)/(r*t) + (2*a.*(b - q))/(r*t.*q^3);
end
for v=1:1000
l(v+1)=l(v)-(fun(l(v))/(der(l(v))));
err(v)=abs((l(v+1)-l(v))/(l(v)));
if err(v)<=0.01
break
end
end
result=l(v+1)
end

Réponses (1)

Meysam Mahooti
Meysam Mahooti le 5 Déc 2019

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by