Hi everyone. I have these two functions. When I run them I get this error : Error using fzero (line 257) Function values at interval endpoints must be finite and real. Thanks in advance. function [Ps,vl,vv]= PRPsat(T,TC,Pc,w) PC=Pc*100000; R=8314; k=0.37464+1.54226*w-0.26992*w^2; aT=(1+k*(1-sqrt(T/TC)))^2; a=aT*0.45724*(R*TC)^2/PC; b=0.07780*R*TC/PC;
cc=[ -R*T, 2*a – 4*R*T*b, – 2*R*T*b^2 – 2*a*b, 4*R*T*b^3 – 2*a*b^2, – R*T*b^4 + 2*a*b^3]; Pr=(R*T./(roots(cc)-b)-a./((roots(cc).^2)+2.*b*(roots(cc)+b.^2)))/PC; Pr=sort(Pr); Psmin=(max(eps,Pr(3))+eps^(1/3))*PC; Psmax=(Pr(4)-eps^(1/3))*PC;
Ps=fzero(@IntMaxwell,[Psmin;Psmax],[],a,b,R,T); [I,vl,vv]=IntMaxwell(Ps,a,b,R,T); Ps=Ps/10000; end
function [I,vl,vv]=IntMaxwell(Psat,a,b,R,T) c=[1, -(-b+(R*T/Psat)),a/Psat-3*b^2-2*b*R*T/Psat, -(a*b/Psat-b^3-(b^2)*R*T/Psat)]; v=real(roots(c)); v=v(v>0); vl=min(v); vv=max(v); I=R*T*log((vv – b)/(vl-b)) – Psat*(vv-vl) + (2^(1/2)*a*(atanh(2^(1/2)/2 + (2^(1/2)*vv)/(2*b)))-atanh(2^(1/2)/2 + (2^(1/2)*vl)/(2*b)))/(2*b); end
Best Answer