1

I have the following function:

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

Here, L,Kc1,Kc2,Kc3 and Kc4 are arrays which already have 99 numerical values stored in them. Thus, I need to solve for x(1) and x(2) 99 times and store them in the arrays O2 and N2. For this, the code is:

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

Ideally, i should have gotten the arrays O2 and N2 by solving these equations. However, when I run my program, I get the following error:

??? 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.

Does anyone know what's wrong? Thanks in advance.

4

1 回答 1

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 将是 size[2 x 1]而不是[1 x 2],并且您的vertcat错误将消失。

于 2013-05-16T17:17:25.703 回答