我有以下功能:
function F = F(x,L,Kc1,Kc2,Kc3,Kc4)
F=[(2*L*x(1)^2)/Kc1 + L*x(1)*x(2)/Kc3 + x(1)+ (x(1)*Kc4/L)^0.5 - (2*(0.235)); (2*L*(x(2)^2))/Kc2 + x(2)+ L*x(1)*x(2)/Kc3 -2*(0.765)];
end
这里,L,Kc1,Kc2,Kc3 and Kc4
是已经存储了99个数值的数组。因此,我需要解决x(1) and x(2)
次99次并将它们存储在数组O2和N2中。为此,代码是:
x0=[-5 -5];
O2=zeros(1,99);
N2=zeros(1,99);
for i=1:1:99
x=fsolve(@(x)F(x,L(i),Kc1(i),Kc2(i),Kc3(i),Kc4(i)),x0);
O2(i)=x(1);
N2(i)=x(2);
end
理想情况下,我应该通过求解这些方程得到阵列O2和N2。但是,当我运行我的程序时,我收到以下错误:
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> F at 2
F=[(2*L*(x(1)^2))/Kc1 + L*x(1)*x(2)/Kc3 + x(1)+ (x(1)*Kc4/L)^0.5 - (2*(0.235)); (2*L*(x(2)^2))/Kc2 +
x(2)+ L*x(1)*x(2)/Kc3 -2*(0.765)];
Error in ==> @(x)F(x,L(i),Kc1(i),Kc2(i),Kc3(i),Kc4(i))
Error in ==> fsolve at 254
fuser = feval(funfcn{3},x,varargin{:});
Error in ==> Air_equilibriuw at 76
x=fsolve(@(x)F(x,L(i),Kc1(i),Kc2(i),Kc3(i),Kc4(i)),x0);
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
有谁知道什么是错的?提前谢谢。
答案 0 :(得分:1)
更改
function F = F(x,L,Kc1,Kc2,Kc3,Kc4)
F=[(2*L*x(1)^2)/Kc1 + L*x(1)*x(2)/Kc3 + x(1)+ (x(1)*Kc4/L)^0.5 - (2*(0.235)); (2*L*(x(2)^2))/Kc2 + x(2)+ L*x(1)*x(2)/Kc3 -2*(0.765)];
end
到
function F = F(x,L,Kc1,Kc2,Kc3,Kc4)
F=[(2*L*x(1)^2)/Kc1 + L*x(1)*x(2)/Kc3 + x(1)+ (x(1)*Kc4/L)^0.5 - (2*(0.235)), (2*L*(x(2)^2))/Kc2 + x(2)+ L*x(1)*x(2)/Kc3 -2*(0.765)];
end
现在F的大小为[2 x 1]
,而不是[1 x 2]
,您的vertcat
错误就会消失。