ode45 Error differential equation system

I'm trying to solve a system of differential equations with ode45 but an appears. Could someone help me spot the mistake(s)?
%%Parameters
R_la= 0.4;
R_sa_b= 5.03;
R_sv= 1.32;
R_lv= 0.56;
P_a_b= 100;
P_v= 6;
V_la=1;
V_sa_b= 12;
P_ic= 10;
Ca= 0.205;
k_ven= 0.186;
P_v1= -2.25;
V_vn= 28;
G_q= 3;
tau_q= 20;
Pa_co2_b= 40;
tau_co2= 40;
%%State parameters
F=@(t,V_sa,P1,P2) [ Ca.*(P1-P_ic);
((P_a_b-P1)./(R_la + 0.5 .*R_sa_b) - (P1-P2)./(0.5 .*R_sa_b+R_sv))./Ca;
((P1-P2)./(0.5 .*R_sa +R_sv)-(P2-P_v)./R_lv)./ (1./(k_ven.*(P2-P_ic-P_v1))) ]
[t,V_sa,P1,P2]= ode45(F,[0 10],[0 0 0]);
q= (P1-P2)./0.5 .*R_sa + R_sv ;
F1=@(t,xq,xc) [ (-xq+G_q .*(q-q_b)./q_b)./tau_q ;
(-xc +0.3+3.*tanh(Pa_co2./Pa_co2_b -1.1))./tau_co2 ]
[t,xq,xc]= ode45(F1,[0 10],[0 0 0]);
Error message:
Not enough input arguments.
Error in
CBF_v2>@(t,V_sa,P1,P2)[Ca.*(P1-P_ic);((P_a_b-P1)./(R_la+0.5.*R_sa_b)-(P1-P2)./(0.5.*R_sa_b+R_sv))./Ca;((P1-P2)./(0.5.*R_sa+R_sv)-(P2-P_v)./R_lv)./(1./(k_ven.*(P2-P_ic-P_v1)))]
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in CBF_v2 (line 37)
[t,V_sa,P1,P2]= ode45(F,[0 10],[0 0 0]);

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Okt. 2017

0 Stimmen

Change
F=@(t,V_sa,P1,P2) [ Ca.*(P1-P_ic);
((P_a_b-P1)./(R_la + 0.5 .*R_sa_b) - (P1-P2)./(0.5 .*R_sa_b+R_sv))./Ca;
((P1-P2)./(0.5 .*R_sa +R_sv)-(P2-P_v)./R_lv)./ (1./(k_ven.*(P2-P_ic-P_v1))) ]
[t,V_sa,P1,P2]= ode45(F,[0 10],[0 0 0]);
to
F = @(t, V_saP1P2) [ Ca.*(V_saP1P2(2)-P_ic);
((P_a_b-V_saP1P2(2))./(R_la + 0.5 .*R_sa_b) - (V_saP1P2(2)-V_saP1P2(3))./(0.5 .*R_sa_b+R_sv))./Ca;
((V_saP1P2(2)-V_saP1P2(3))./(0.5 .*R_sa +R_sv)-(V_saP1P2(3)-P_v)./R_lv)./ (1./(k_ven.*(V_saP1P2(3)-P_ic-P_v1))) ];
[t, V_saP1P2] = ode45(F, [0 10], [0 0 0]);
V_sa = V_saP1P2(:,1);
P1 = V_saP1P2(:,2);
P2 = V_saP1P2(:,3);
and similar changes for your F1

8 Kommentare

Thank you for your help but I still get the error:
Not enough input arguments.
Error in
CBF_v2>@(t,V_sa,P1,P2)[Ca.*(P1-P_ic);((P_a_b-P1)./(R_la+0.5.*R_sa_b)-(P1-P2)./(0.5.*R_sa_b+R_sv))./Ca;((P1-P2)./(0.5.*R_sa+R_sv)-(P2-P_v)./R_lv)./(1./(k_ven.*(P2-P_ic-P_v1)))]
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in CBF_v2 (line 36)
[t, V_saP1P2] = ode45(F, [0 10], [0 0 0]);
Torsten
Torsten am 13 Okt. 2017
The error message clearly shows that you didn't incorporate Walters's changes.
Best wishes
Torsten.
gorilla3
gorilla3 am 13 Okt. 2017
I'm sorry I just replaced the 2nd part of the code at frist. It works now, thank you both!
gorilla3
gorilla3 am 24 Okt. 2017
Bearbeitet: gorilla3 am 24 Okt. 2017
Hi,
I'm sorry for troubling you again but I realized that I didn't express the 1st eq correctly. It should stand for:
  • d/dt (V_sa)= d/dt(Ca*(P1-P_ic))
However, I'm unsure on how to express d/dt P1 in the equation, since that itself is an equation of the system.
Could you help me reformulate it please? It would be great!
This means that
V_sa(t) = V_sa(t=0) + Ca*(P1(t)-P1(t=0))
So you don't need to include V_sa in your system of equations.
Best wishes
Torsten.
gorilla3
gorilla3 am 24 Okt. 2017
But if I elaborate: d/dt V_sa= d/dtCa * (P1-P_ic) + Ca* d/dt (P1- P_ic).
where Ca and P_ic are numbers so their derivative is 0, but P1 is not a number. Indeed, one of the equations in the system is:
  • d/dt P1 = ( (P_a_b-P1)/(R_la+0.5*R_sa_b) - (P1-P2)/(0.5*R_sa_b+R_sv) )/Ca_b
So I can't just remove V_sa.
My question is how to express:
  • d/dtCa * (P1-P_ic) + Ca* d/dt (P1- P_ic)
as the 1st equation of the system, since I can't use the d/dt symbol in it.
gorilla3
gorilla3 am 24 Okt. 2017
Hi Torsten,
in case you find my last comment confusing, here is a better overview: https://uk.mathworks.com/matlabcentral/answers/362979-ode-45-formulation-of-equations-in-system
Thanks again!
Integrating your first equation from t'=0 to t'=t gives
V_sa(t)-V_sa(0)= Ca*(P1(t)-P_ic) - Ca*(P1(0)-P_ic)
This means that V_sa(t) can be expressed by P1(t) as
V_sa(t)=
V_sa(0)+ Ca*(P1(t)-P_ic) - Ca*(P1(0)-P_ic)=
V_sa(0)+Ca*(P1(t)-P1(0))
Consequently, you don't need to include a differential equation for V_sa in your system. The solution can be derived from the solution for P1 by the formula from above.
If you insist on solving a differential equation for V_sa:
d/dt(V_sa) = d/dt(Ca*(P1-P_ic)) = Ca*d/dt(P1)
Now for d/dt(P1), insert the expression from the right-hand side of the differential equation for P1.
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by