Newton-Raphson Method Error
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!