fzero instead of Newton-Raphson method in flash calculations!
4 views (last 30 days)
Show older comments
Hi
I am trying to do some flash calculations using Newtons method to define alpha.
But if i change the pressure i need to update the guess value to something very close (+/- 0.1), this is not allways possible! Is there a way to the following in another way like using fzero?
%Step two Newton-Raphson--------------------------------------------------%
alpha = 0.1; %Initial guess
epsilon2 = 1.0; %initial errors to start loops
while (epsilon2 >= 1.e-12); %Newton-Raphson while loop
h = 0; dh = 0; %Starting value for h and dh
for i=1:nc
h = z(i)*(K(i)-1)/(1+alpha*(K(i)-1))+h; %Iteration of alpha
dh = -(z(i)*(K(i)-1)^2/(1+alpha*(K(i)-1))^2+dh);%Iteration for next alpha
end
alphan = alpha - (h / dh); %Update alpha
epsilon2 = abs( (alphan-alpha)/alpha ); %Update error value
alpha = alphan; %Update alpha
end
4 Comments
Answers (2)
MEL
on 7 May 2015
Dear Dennis,
I used your code some time ago for a flash calculation. I think that you meant (in your comment) the following line:
while (episilon1 >= 1.e-12); %K-value while loop
instead of:
%while (episilon1 >= 1.e-12); %K-value while loop
because you have two "end"s after... However, I concluded that the use of two nested cycle is useless if you calculate the new K with a separate function that takes the current composition to calculate the new "K" inside the Newton-Raphson while. Tell me your opinion about this:
- you estimate the first K
- you calculate alpha
- you calculate a new K with the new composition (given by the new alpha)
and so iteratively until you achieve the convergent values of alpha and K.
Of course, this is valid if you calculate K by means of fugacities. If your K is indipendent from your current composition (for example taking K = vapur pressure_i /total pressure) my, but even more yours, argument is completely useless.
Thanks!
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!