Newton-Raphson Method Error

1 回表示 (過去 30 日間)
mPackEE
mPackEE 2015 年 2 月 19 日
回答済み: Meysam Mahooti 2019 年 12 月 5 日
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

回答 (1 件)

Meysam Mahooti
Meysam Mahooti 2019 年 12 月 5 日

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by