Ayuda ODE45 con condición If

4 visualizaciones (últimos 30 días)
Cesar García
Cesar García el 14 de Dic. de 2015
Comentada: Cesar García el 20 de Dic. de 2015
Saludos,
Estoy tratando de resolver en set de ODEs usando ODE45, el problema es que algunos estados que dependen del tiempo tienes restricciones las cuales debo definir con if.
condiciones iniciales:
x0=[0.43 5 0.58 0.14 0.0024 0.01 4];
Condición inicial para el estado que no depende del tiempo
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
condiciones para los estados que dependen del tiempo
if x(3)<0.15
x(3)=0.15;
end
if x (5)<0.002432
x(5)=0.002432;
end
aprecio su ayuda.
Gracias
Best Regards.

Respuesta aceptada

Star Strider
Star Strider el 14 de Dic. de 2015
I did not run your code, and I do not follow what you are doing. However, looking at it I have two observations:
1. I do not know what tspan is, but the ODE solvers do not do well with discontinuities with respect to time. For example, I would break your ODE integration time into:
tspan1 = [ 0 24];
tspan2 = [24 30];
tspan3 = [30 60];
or whatever you want the third interval to be. Use the last values of ‘x’ of the previous interval as the initial values for the next interval. That way, ode45 does not have to integrate over the discontinuities.
2. If you want to limit ‘x(3)’ and ‘x(5)’, it is easier to use the max function than if blocks:
x(3) = max(x(3), 0.015);
x(5) = max(0.002432, x(5));

Más respuestas (1)

Cesar García
Cesar García el 15 de Dic. de 2015
Thank you for your response, i am traying to pass from euler to ode45 solution technique. Attached is the eulers method.
I appreciate your help.
  10 comentarios
Star Strider
Star Strider el 16 de Dic. de 2015
It should be relatively easy to apply it to (8) and (9) if you already have the code (as functions of time) for the rest of it.
I have been working on this intermittently and cannot find some necessary information. I cannot figure out how to get an expression in time for ‘Jf’. The ODE functions return time to the ODE you are integrating, so writing a function to return a time-dependent value for ‘Jf’ (and therefore ‘Jm’) would be straightforward if I already had an expression in time for the functions you use to calculate it.
The infinite sum for ‘Pn’ is another problem, but lacking a function for ‘Jf’ renders it irrelevant.
So while I have an idea of how to do it, without the requisite background information, I cannot write a function to use in ode15s to integrate it.
Also, this would likely be easier to implement in SimBiology if you have access to it.
Cesar García
Cesar García el 20 de Dic. de 2015
Hi,
well, Jf(t) is a function of the states (X,S, N and so on), we get a value based in the solution of the dynamics states.
i will check the simbiology.
Thank you very much

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by