Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

help with this type of ode45

2 views (last 30 days)
Cesar García
Cesar García on 14 Dec 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi,
I am trying to solve a set of differential equations using ode45, the problem is that i need to define some if conditions and a state that does not depend of the time.
Initial conditions for time dependent states
x0=[0.43 5 0.58 0.14 0.0024 0.01 4];
Initial conditions for non-time dependent state
u(1)=um*((x0(3)/x0(2))/((x0(3)/x0(2))+Ksr))*(1-((x0(3)/x0(2))/Sm)^nk)*((x0(5)/(Kox*x0(1)+x0(5))));
Time definition
tsim=50;
dt=0.0001;
t(1)=0;
i=1;
Ni=round(tsim/dt);
for i=1:Ni
if t(i)<24
F1=0;
F2=0;
elseif t(i)>24 && t(i)<30
F1=80*(1/1000);
F2=0;%70*(1/1000);
else
F1=0;
F2=0;
end
dx=@(t,x) [u(i)*x(1)-((F1+F2)/x(7))*x(1);
-((Csx*u(i)*x(1))+(Rcsx*x(1))+Csp*((k1*u(i)*x(1))+(k2*x(1))))+(F1/x(7))*Sin-((F1+F2)/x(7))*x(2);
-((Cnx*u(i)*x(1))+(Rcnx*x(1)))+(F2/x(7))*Nin-((F1+F2)/x(7))*x(3);
((k1*u(i)*x(1))+(k2*x(1)))-((F1+F2)/x(7))*x(4);
((KL*(O2Leq-x(5)))-(k3*u(i)*x(1))-((k4*k1*u(i)*x(1))+(k4*k2*x(1))))+(F3/x(7))*O2in-((F1+F2)/x(7))*x(5);
((alfa1*u(i)+alfa2)*x(1))+(alfa3)-((F1+F2)/x(7))*x(6);
(F1+F2)];
[t,x]=ode45(dx,tspan,x0);
u(i+1)=um*((x(3)/x(2))/((x(3)/x(2))+Ksr))*(1-((x(3)/x(2))/Sm)^nk)*((x(5)/(Kox*x(1)+x(4))));
if u(i+1)<0
u(i+1)=0;
end
t(i+1)=t(i)+dt;
i=i+1;
end
besides, i need to define some if conditions for time dependent states
if x(3)<0.15
x(3)=0.15;
end
if x (5)<0.002432
x(5)=0.002432;
end
I´ll appreciate your help with this.
Best Regards.

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!