Why does my answer converges? "iterations"
Mostrar comentarios más antiguos
I'm currently trying to solve a cubic equation of state "SRK" to find compressibility factor Z. Moving aside from physics, my iteration doesn't converages for liquid at all and for vapour at small pressure less than 30 bar for a state of compound 1 alone. Find attached the code. Most of it at the begining is just some parameters for the solution. so, I will include the condition.
z_vold=1;
z_lold=beta_l;
z_lnew=beta_l+(z_lold+epi*beta_l).*(z_lold+sig*beta_l)*(1+beta_l-z_lold)/(q_l*beta_l);
z_vnew=1+beta_v-q_v.*beta_v.*(z_vold-beta_v)./((z_vold+epi.*beta_v).*(z_vold-sig.*beta_v));
% error in vapour doesn't converge for high pressures till 30 bar for
% compound1
% error in liquid doesn't converge except for higher pressures
while 1 %z_v loop
error_v=(z_vold-z_vnew)./z_vnew;
if abs(error_v)<=0.001
break
else
z_vold=z_vnew;
z_vnew=1+beta_v-q_v.*beta_v.*(z_vold-beta_v)./((z_vold+epi.*beta_v).*(z_vold-sig.*beta_v));
end
end
while 1 %z_l loop
error_l=(z_lold-z_lnew)./z_lnew;
if abs(error_l)<=0.001
break
else
z_lold=z_lnew;
z_lnew=beta_l+(z_lold+epi*beta_l).*(z_lold+sig*beta_l)*(1+beta_l-z_lold)/(q_l*beta_l);
end
end
Respuestas (1)
Roger Stafford
el 14 de Jun. de 2016
0 votos
You are apparently trying to solve a quadratic equation in z_v and a cubic equation in z_l. Instead of using the highly questionable iteration you have set up here, you should put the two equations in standard form with like powers of the z’s collected and solve these equations with matlab’s ‘roots’ function. (Of course with the quadratic equation you can also use the formula we all learned in high school.) You may get multiple real roots but it will be up to you to select the valid ones.
Categorías
Más información sobre Thermodynamics and Heat Transfer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!