double type fzero error in vapor pressure calc

1 回表示 (過去 30 日間)
James Burrow
James Burrow 2016 年 2 月 22 日
回答済み: Torsten 2016 年 2 月 22 日
%%%Hi, pretty new with MatLab but think I understand what I'm doing, for some reason keep getting an error about 'double' type arguments in the fzero function.
%%%I made this mfile to define function for which I need the root:
function y=deltaphi(Pguess)
Tc=507.6;%K
Pc=30.25;%bar
w=0.301;
T=341.9%K
R=8.3144598*10^(-5);%m3 bar / K mol
f=0.480+1.574*w-0.176*w^2;
ac=0.42748*(R^2)*(Tc^2)/Pc;
a=ac*(1+f*(1-(T/Tc)^(1/2)))^2;
b=0.08664*R*Tc/Pc;
syms V
SRK=Pguess==R*T/(V-b)-a/(V*(V-b));
V=solve(SRK,V,'Real',true)
V=V(V>0)
Vl=double(min(V))
Vv=double(max(V))
Zl=R*T/(Pguess*Vl)
Zv=R*T/(Pguess*Vv)
phi_l=exp(Zl-1-log(Zl)-log(1-b/Vl)-(a/(b*R*T))*log(1+b/Vl))
phi_v=exp(Zl-1-log(Zl)-log(1-b/Vv)-(a/(b*R*T))*log(1+b/Vv))
y=phi_l/phi_v-1
end
%%%%Then I wrote this script file to find a good starting point for the fzero function: R=8.3144598*10^(-5);
T=341.9;
a=3.*10^(-5);
b=1.2088*10^(-4);
syms V
SRK=R*T/(V-b)-a/(V*(V-b));
Vext=solve(diff(SRK,'V')==0,V,'Real',true);
Vext=Vext(Vext>b);
Vmax=max(Vext);
Vmin=min(Vext);
Pmin=max(10*(-7),R*T/(Vmin-b)-a/(Vmin*(Vmin-b)))
Pmax=max(R*T/(Vmax-b)-a/(Vmax*(Vmax-b)))
Pguess=Pmin:0.99*Pmax
Pvap=fzero(@deltaphi,double(Pguess))
%%%Any help would be much appreciated. This is the exact error message
"Error using fzero (line 412) Second argument must be a scalar or vector of length 2.
Error in pvap (line 14) Pvap=fzero(@deltaphi,double([Pmin:0.99*Pmax]))"

回答 (1 件)

Torsten
Torsten 2016 年 2 月 22 日
And - is double(Pguess) a scalar or a vector of length 2 ? No, it isn't.
As the second argument in the call to fzero, you have to supply a starting guess or a starting interval for the solution, thus a scalar or a vector of length 2.
Best wishes
Torsten.

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by