Problem with my gamma_water values not giving me the correct pressure using fsolve

2 views (last 30 days)
Hi,
I'm having trouble with my "gamma_water" variable not giving me the correct P (PressureNonIdeal) value. I keep getting this message : No solution found.
fsolve stopped because the
last step was ineffective. However, the vector of function
values is not near zero, as measured by the value of the
Here is my current code :
DelH = -1* (-917.475 - (-600.351 + -247.184)) * 1000;
DelS = -1*(172.10 - (76.87 + 232.70));
DelV = -1*(((24.630 - (11.248))*1E-6) *1E5);
Grxn = 0; %because at equilibrium
R = 8.314;
T=948.15; %675 C
x0 = 2000;
fun = @DeltaGcalc;
%Ideal gas
gamma_water = 1
PressureIdeal=fsolve(@(P) fun(DelH,DelS,DelV,T,P,R,gamma_water),x0)
%Non-ideal gas
Ta = 873.15 ; ga = 0.5203; %For a constant pressure of 2000bar
Tb = 1273.15 ; gb = 0.7939;
gamma_water = ((gb-ga)/(Tb-Ta))*T;
PressureNonIdeal=fsolve(@(P) fun(DelH,DelS,DelV,T,P,R,gamma_water),x0)
function Grxn = DeltaGcalc(DelH,DelS,DelV,T,P,R,gamma_water)
Grxn = DelH - T*DelS + DelV*(P-1) + R*T*log(gamma_water*P); %because both the solids are pure, their activity is 1. the activity of the fluid only counts.
end
According to the question, «The pressure (PressureNonIdeal) for the value calculated with the fugacity coefficient (gamma_water) will be between 2 and 10 kbar (200 to 1 000 MPa). Note that you will have to interpolate between the values in the tables, both in terms of pressure and temperature; between any two values in the table at either constant pressure or at constant temperature you can assume that the variations are linear.»
I have attached the table to this description

Answers (1)

Torsten
Torsten on 21 Sep 2024
Look at the curves and see what's happening. Your first equation has two solutions while your second has none:
DelH = -1* (-917.475 - (-600.351 + -247.184)) * 1000;
DelS = -1*(172.10 - (76.87 + 232.70));
DelV = -1*(((24.630 - (11.248))*1E-6) *1E5);
Grxn = 0; %because at equilibrium
R = 8.314;
T=948.15; %675 C
x0 = 2000;
fun = @DeltaGcalc;
%Ideal gas
gamma_water = 1;
PressureIdeal=fsolve(@(P) fun(DelH,DelS,DelV,T,P,R,gamma_water),x0)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
PressureIdeal = 4.8188e+03
x=4e3:10:8e3;
figure()
plot(x,fun(DelH,DelS,DelV,T,x,R,gamma_water))
%Non-ideal gas
Ta = 873.15 ; ga = 0.5203; %For a constant pressure of 2000bar
Tb = 1273.15 ; gb = 0.7939;
gamma_water = ((gb-ga)/(Tb-Ta))*T;
PressureNonIdeal=fsolve(@(P) fun(DelH,DelS,DelV,T,P,R,gamma_water),x0)
No solution found. fsolve stopped because the last step was ineffective. However, the vector of function values is not near zero, as measured by the value of the function tolerance.
PressureNonIdeal = 5.8907e+03
x=0.1:100:1e4;
figure()
plot(x,fun(DelH,DelS,DelV,T,x,R,gamma_water))
function Grxn = DeltaGcalc(DelH,DelS,DelV,T,P,R,gamma_water)
Grxn = DelH - T*DelS + DelV*(P-1) + R*T*log(gamma_water*P); %because both the solids are pure, their activity is 1. the activity of the fluid only counts.
end
  8 Comments
Torsten
Torsten on 21 Sep 2024
May it be the case that your equation uses a normalized pressure instead of absolute pressure ? The term DelV*(P-1) for P in the order of 2000 bar looks quite strange to me...
Mathys
Mathys on 21 Sep 2024
Edited: Mathys on 21 Sep 2024
@Torsten I do not know the pressure, so don't think this is it. In fact, the pressure is what I am looking to obtain. I just know that the PressureNonIdeal will be between 2000 bar and 10000 bar, hence my initial guess of 2000 bar in fsolve. My PressureIdeal value is correct, according to MatLab Grader

Sign in to comment.

Categories

Find more on Thermal Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!