How to Solve 13 ODEs simultaneously by ode45
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i need to solve 13 ODEs ,all are interdependent, i need to solve it using ode45 and tgen plot it but the error is it says index is more than 12
Any help on this is highly appreciated.
qgin=12;
c_g_in=[1 2 3 4 5 6 ];
c=zeros(13,1);
c_l_in=[1 3 5 7 3 5 ];
vg=27;
kla=[13 34 5 6 7 7 ];
vl=65;
m=[23 3 5 2 1 4];
ql=123;
v_max=[1 2 3 5 7 1];
for i=1:6
v(i)=-v_max(i).*c(i);
end
xp=45;
yxco=12;
yxh2=5;
mu=-v(1)*yxco-v(2)*yxh2;
kd=15;
c0=[1 2 3 0 0 0 0 0 0 2 5 6 13];
c0g=c0(1:6);
ngout=qgin*sum(c_g_in,'all')-kla(1)*((c(1)/m(1))-c(7))*vl-kla(2)*((c(2)/m(2))-c(8))*vl-kla(3)*((c(3)/m(3))-c(9))*vl+kla(4)*((c(10)/m(4))-c(4))*vl+kla(5)*((c(11)/m(5))-c(5))*vl+kla(6)*((c(12)/m(6))-c(6))*vl;
qgout=ngout*R*t/(sum((psat.*c0g),'all'));
f=@(t,c)[((qgin.*c_g_in(1)-qgout.*c(1))./vg)-kla(1).*(vl/vg).*((c(1)./m(1))-c(7)),
((qgin.*c_g_in(2)-qgout.*c(2))./vg)-kla(2).*(vl/vg).*((c(2)./m(2))-c(8)),
((qgin.*c_g_in(3)-qgout.*c(3))./vg)-kla(3).*(vl/vg).*((c(3)./m(3))-c(9)),
((qgin.*c_g_in(4)-qgout.*c(4))/vg)+kla(4).*(vl/vg).*((c(10)./m(4))-c(4)),
((qgin.*c_g_in(5)-qgout.*c(5))/vg)+kla(5).*(vl/vg).*((c(11)./m(5))-c(5)),
((qgin.*c_g_in(6)-qgout.*c(6))/vg)+kla(6).*(vl/vg).*((c(12)./m(6))-c(6)),
((ql/vl).*(c_l_in(1)-c(7))+kla(1).*((c(1)./m(1))-c(7))+v(1).*c(13)),
((ql/vl).*(c_l_in(2)-c(8))+kla(2).*((c(2)./m(2))-c(8))+v(2).*c(13)),
((ql/vl).*(c_l_in(3)-c(9))+kla(3).*((c(3)./m(3))-c(9))+v(3).*c(13)),
((ql/vl).*(c_l_in(4)-c(10))-kla(4).*((c(10)./m(4))-c(4))+v(4).*c(13)),
((ql/vl).*(c_l_in(5)-c(11))-kla(5).*((c(11)./m(5))-c(5))+v(5).*c(13)),
((ql/vl).*(c_l_in(6)-c(12))-kla(6).*((c(12)./m(6))-c(6))+v(6).*c(13)),
((ql/vl).*(-c(13).*xp)+mu.*c(13)-kd.*c(13))]
tspan=[0 600];
[t,c]=ode45(f,tspan,c0);
error is as follows
f =
function_handle with value:
@(t,c)[((qgin.*c_g_in(1)-qgout.*c(1))./vg)-kla(1).*(vl/vg).*((c(1)./m(1))-c(7));((qgin.*c_g_in(2)-qgout.*c(2))./vg)-kla(2).*(vl/vg).*((c(2)./m(2))-c(8));((qgin.*c_g_in(3)-qgout.*c(3))./vg)-kla(3).*(vl/vg).*((c(3)./m(3))-c(9));((qgin.*c_g_in(4)-qgout.*c(4))/vg)+kla(4).*(vl/vg).*((c(10)./m(4))-c(4));((qgin.*c_g_in(5)-qgout.*c(5))/vg)+kla(5).*(vl/vg).*((c(11)./m(5))-c(5));((qgin.*c_g_in(6)-qgout.*c(6))/vg)+kla(6).*(vl/vg).*((c(12)./m(6))-c(6));((ql/vl).*(c_l_in(1)-c(7))+kla(1).*((c(1)./m(1))-c(7))+v(1).*c(13));((ql/vl).*(c_l_in(2)-c(8))+kla(2).*((c(2)./m(2))-c(8))+v(2).*c(13));((ql/vl).*(c_l_in(3)-c(9))+kla(3).*((c(3)./m(3))-c(9))+v(3).*c(13));((ql/vl).*(c_l_in(4)-c(10))-kla(4).*((c(10)./m(4))-c(4))+v(4).*c(13));((ql/vl).*(c_l_in(5)-c(11))-kla(5).*((c(11)./m(5))-c(5))+v(5).*c(13));((ql/vl).*(c_l_in(6)-c(12))-kla(6).*((c(12)./m(6))-c(6))+v(6).*c(13));((ql/vl).*(-c(13).*xp)+mu.*c(13)-kd.*c(13))]
Error using odearguments (line 113)
Inputs must be floats, namely single or
double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed,
solver_name, ode, tspan, y0, options,
varargin);
Error in gshs (line 36)
[t,c]=ode45(f,tspan,c0);
2 commentaires
James Tursa
le 23 Fév 2021
Modifié(e) : James Tursa
le 23 Fév 2021
Please format your code so that it is readable. Also copy & paste the entire error message for us to read, including the offending line.
Réponses (1)
James Tursa
le 23 Fév 2021
Modifié(e) : James Tursa
le 23 Fév 2021
Your c0 has only 12 elements. It needs to have 13 elements.
5 commentaires
James Tursa
le 24 Fév 2021
Most contributors here don't like to make assumptions about code ... especially when the entire code isn't shown and there are errors involved. We prefer to copy & run complete code that reproduces the error so that we can decipher for sure what is causing the error.
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!