MATLAB: System of 5 eq and 5 uknowns, FSOLVE error

fsolvesystem of equations

Hi,
I have an error in the initial condition (B0) estimation but don't know how to solve it. How does one choose the initial parameters of the solution? I only gave it random values… here's the code:
load constants
syms Rsa Vsa P3 q Psa real
e1= Rsab/(Vsa/Vsab)^2 -Rsa;
e2= Csa*(Psa-Pic) -Vsa;
e3= q*Rlv+Pvb-P3;
e4= (Psa-P3)/(Rsv+0.5*Rsa+Rnet) -q;
e5= ABP-q*(Rla+0.5*Rsa)-Psa;
Eqnsfcn = matlabFunction([e1, e2, e3, e4, e5], 'Vars',{[Rsa, Vsa, P3, q, Psa]});
B0 = rand(1,5)*100; %initial parameters
[B,fval] = fsolve(@(b)Eqnsfcn(b(1),b(2),b(3),b(4),b(5)), B0);
Bc = num2cell(B);
[Rsa, Vsa, P3, q, Psa] = Bc{:}
this is the error I get is below. Could you please help me get real solutions of these equations? Thanks!
Error using
symengine>@(in1)[-in1(:,1)+1.0./in1(:,2).^2.*2.145016313856e-4,in1(:,5).*3.7e-8-in1(:,2)-3.7e-7,-in1(:,3)+in1(:,4).*1.8928e6+6.0,-in1(:,4)-(in1(:,3)-in1(:,5))./(in1(:,1).*(1.0./2.0)+9.024393684230502e15),-in1(:,5)-in1(:,4).*(in1(:,1).*(1.0./2.0)+1.352e6)+1.0e2]
Too many input arguments.
Error in eqsystem_O2_15_04_19_v1>@(b)Eqnsfcn(b(1),b(2),b(3),b(4),b(5))
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Error in eqsystem_O2_15_04_19_v1 (line 48)
[B,fval] = fsolve(@(b)Eqnsfcn(b(1),b(2),b(3),b(4),b(5)), B0);
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

Best Answer

There are a few errors in your posted code.
Corrected:
syms Rsa Vsa P3 q Psa Rsab Vsab Csa Pic Rsv Rlv Pvb Rnet ABP Rla real
V = load('constants.mat');
Rsab = V.Rsab;
Vsab = V.Vsab;
Csa = V.Csa;
Pic = V.Pic;
Rsv = V.Rsv;
Rlv = V.Rlv;
Pvb = V.Pvb;
Rnet = V. Rnet;
ABP = V.ABP;
Rla = V.Rla;
e1= Rsab/(Vsa/Vsab)^2 -Rsa;
e2= Csa*(Psa-Pic) -Vsa;
e3= q*Rlv+Pvb-P3;
e4= (Psa-P3)/(Rsv+0.5*Rsa+Rnet) -q;
e5= ABP-q*(Rla+0.5*Rsa)-Psa;
Eqnsfcn = matlabFunction([e1, e2, e3, e4, e5], 'Vars',{[Rsa, Vsa, P3, q, Psa]});
B0 = rand(1,5)*100; %initial parameters
[B,fval] = fsolve(Eqnsfcn, B0);
Bc = num2cell(B);
[Rsa, Vsa, P3, q, Psa] = Bc{:}
The fsolve function requests that you allow it more function evaluations (and probably more iterations as well). You can do that with the optimoptions (link) function.