system of 5 eq and 5 uknowns, FSOLVE error
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
gorilla3
am 15 Apr. 2019
Kommentiert: Star Strider
am 16 Apr. 2019
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 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Apr. 2019
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 Kommentare
Star Strider
am 16 Apr. 2019
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genomics and Next Generation Sequencing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!