Ayuda ODE45 con condición If
Mostrar comentarios más antiguos
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
Más respuestas (1)
Cesar García
el 15 de Dic. de 2015
0 votos
10 comentarios
Star Strider
el 15 de Dic. de 2015
I cannot make sense out of that. I would appreciate your uploading a description of your problem as a PDF file or other description of your problem.
Cesar García
el 15 de Dic. de 2015
Star Strider
el 15 de Dic. de 2015
It would take me weeks to understand that, even considering that I have a relatively strong (although not current) background in chemistry and biochemistry, so I will leave the details to you. My background is not sufficient to understand that paper.
What parts do you need help on? It is probably best for me to help you with the MATLAB coding. The paper is necessary because it is easier for me to read the relevant parts and ask you about them. It will take a bit of time regardless.
Cesar García
el 15 de Dic. de 2015
Star Strider
el 15 de Dic. de 2015
What equations in the paper do you want to integrate? (Please be aware that biochemical engineering is very far from my areas of expertise.)
I will look through the code you posted for the constants.
Cesar García
el 15 de Dic. de 2015
Star Strider
el 15 de Dic. de 2015
Eq (8) is probably straightforward if we can assume the summation of Pn is a constant. What is Jm(t)? Do you have a function expression for it as defined in (12)?
I have to admit that I do not understand (A2)-(A4) at all. They apparently have to be iterated over j, and the summation done at each step would be a constant. You would have to put these in a loop with a fixed vector of integration times, and then store each vector of results, most easily in a cell array although a matrix would work as well. It will obviously not be possible to iterate (A3) an infinite number of times.
The ode15s function would seem to me to be the obvious choice for these. but they will not be straightforward to code.
Cesar García
el 15 de Dic. de 2015
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.
Cesar García
el 20 de Dic. de 2015
Categorías
Más información sobre Scan Parameter Ranges en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!