system of 5 eq and 5 uknowns, FSOLVE error
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Star Strider
2019-4-15
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.
6 个评论
Star Strider
2019-4-16
I am lost.
What do you want to do with ‘ABP’? If you want to change it in every iteration of fsolve, delete it from your syms list, create it as an additional parameter, add it to the argument list, and change it in a loop that evaluates ‘Eqnsfcn’.
First eliminate ‘ABP’ as a defined constant (comment it out), and chnange its name in the symbolic code to prevent later conflicts. Then, add it to the 'Vars' name-value pair as a separate argument (not one you want in the parameter vector), and then call fsolve in a loop.
Try this:
syms Rsa Vsa P3 q Psa Rsab Vsab Csa Pic Rsv Rlv Pvb Rnet ABPs 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= ABPs-q*(Rla+0.5*Rsa)-Psa;
Eqnsfcn = matlabFunction([e1, e2, e3, e4, e5], 'Vars',{[Rsa, Vsa, P3, q, Psa],ABPs});
B0 = rand(1,5); %initial parameters
options = optimoptions(@fsolve, 'MaxFunctionEvaluations',150000, 'MaxIterations',15000);
ABPv = 60:0.1:180;
[Rsa, Vsa, P3, q, Psa] = deal(zeros(1, numel(ABPv))); % Preallocate
for i=1:length(ABPv)
[B,fval(i,:)] = fsolve(@(b)Eqnsfcn(b,ABPv(i)), B0, options);
Rsa(i) = B(1);
Vsa(i) = B(2);
P3(i) = B(3);
q(i) = B(4);
Psa(i) = B(5);
end
That worked when I tested it.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genomics and Next Generation Sequencing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!