How to Solve 13 ODEs simultaneously by ode45

1 visualización (últimos 30 días)
Sumeet Sinha
Sumeet Sinha el 23 de Feb. de 2021
Comentada: Sumeet Sinha el 24 de Feb. de 2021
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 comentarios
James Tursa
James Tursa el 23 de Feb. de 2021
Editada: James Tursa el 23 de Feb. de 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.
Sumeet Sinha
Sumeet Sinha el 23 de Feb. de 2021
thank you james for pointing out,was helpful but the problem of unable to solve 13odes still remains after the correction

Iniciar sesión para comentar.

Respuestas (1)

James Tursa
James Tursa el 23 de Feb. de 2021
Editada: James Tursa el 23 de Feb. de 2021
Your c0 has only 12 elements. It needs to have 13 elements.
  5 comentarios
James Tursa
James Tursa el 24 de Feb. de 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.
Sumeet Sinha
Sumeet Sinha el 24 de Feb. de 2021
i have been trying to solve this code for past 12 hrs but unable to point out the error evenafter replacing all constants with its trailing zero
below is the code changing integer to float
qgin=12.000;
c_g_in=[1.000 2.000 3.000 4.000 5.000 6.000 ];
c=zeros(13,1);
c_l_in=[1.000 3.000 5.000 7.000 3.000 5.000];
vg=27.000;
kla=[13.000 34.000 5.000 6.000 7.000 7.000 ];
vl=65.000;
m=[23.000 3.000 5.000 2.000 1.000 4.000];
ql=123.000;
v_max=[1.000 2.000 3.000 5.000 7.000 1.000];
for i=1:6
v(i)=-v_max(i).*c(i);
end
xp=45.000;
yxco=3.000;
yxh2=5.000;
mu=-v(1)*yxco-v(2)*yxh2;
kd=15.000;
c0=[1.000 2.000 3.000 0.000 0.000 0.000 0.000 0.000 0.000 2.000 5.000 6.000 13.000];
c0g=c0(1:6);

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by