clear all
clc
x1 = [100 94.83 85.09 77.33 63.28 53.17 45.03 32.8 19.62 18.17 3.7 2.44 1.18 0]
x2 = 100 - x1
T = [414.75 408.35 406.95 404.24 385.15 376.71 368.45 345.38 338.38 333.18 328.58 326.65 320.65 318.15]
a1 = [4.02291,1221.781,-45.739];
a2 = [4.19518,1649.55,-59.836];
Ps1 = Psat(T,a1)
Ps2 = Psat(T,a2)
% 非线性最小二乘法(非线性数据拟合)
lb = [0 0];
ub = [+inf +inf];
beta0 = [1 1];
[beta,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(@ObjFunc,beta0,lb,ub,[],x1,x2,Ps1,Ps2)
ci = nlparci(beta,residual,jacobian)
[P1,P2,Pcal] = PressureCal(beta,x1,x2,Ps1,Ps2);
y1 = P1./Pcal;
% ------------------------------------------------------------------
function f = ObjFunc(A,x1,x2,Ps1,Ps2)
[P1,P2,Pcal] = PressureCal(A,x1,x2,Ps1,Ps2);
f = Pcal - 300;
% ------------------------------------------------------------------
function [P1,P2,Pcal] = PressureCal(A,x1,x2,Ps1,Ps2)
gamma1 = exp(A(1)*x2./x1+A(1)*x2)./(40*(x1+A(1)*x2)*exp(A(2)*x2./A(2)*x1+x2));
gamma2 = exp(A(2)*x1./x2+A(2)*x1)./(40*(x2+A(2)*x1)*exp(A(1)*x1./A(1)*x2+x1));
P1 = x1.*gamma1.*Ps1;
P2 = x2.*gamma2.*Ps2;
Pcal = P1 + P2;
% ------------------------------------------------------------------
function Ps = Psat(T,a)
% Calculation of the saturation pressure of component i
% T = temperature,℃
% a (vector) = Antoine constants of component i
logPs = a(1)-a(2)./(T+a(3))
Ps = exp(log(10)*logPs)
程序错误如下:
??? Error using ==> f:/matlab/toolbox/optim/private/lsqncommon
User supplied function failed with the following error:
Error using ==> *
Inner matrix dimensions must agree.
Error in ==> F:\matlab\toolbox\optim\lsqnonlin.m
On line 121 ==> [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> F:\tools\1548\1548\Examples\Chapter 7\VLE.m
On line 32 ==> [beta,resnorm,residual,exitflag,output,lambda,jacobian] = ...
望高手赐教,小弟在线等
谢谢了!!!!!!!!!!!!!!!!!!