MATLAB Answers


In ODE solver how to use the time step of each iteration within the differential equation?

Asked by Indu Muthancheri on 14 Jun 2018
Latest activity Commented on by James Tursa
on 14 Jun 2018
One of my differential equation contains a term deltat. How do I access the time step of every ode solver iteration within the differential equation function.
%%in function xx
function dydt=xx(t,y)
dydt(1)=A*deltat; %deltat is the time step during that iteration
Thank you so much in advance for the help!


Your differential equation may contain something like "dy/dt" etc when written out, but that dt is NOT the time step used by the numerical integrator! This is simply derivative notation. What is the DE you are trying to solve?
I am trying for mass balance, which requires the amount of gas in the chamber at that interval of time. So that is (flowrate_of_gas x deltat). The flow rate is fixed, so this is deltat not a differential equation.

Sign in to comment.




2 Answers

Answer by Jan
on 14 Jun 2018

deltat is the time step during that iteration
This is not a meaningful statement. Remember that ODE45 evaluates the equation several times for each step. Afterwards it uses an error control and rejects a step, when the tolerances are exceeded. It is impossible, that the mathematical notation will or can consider this. So please explain exactly, which mathematical problem you want to solve.


If delta_t would depend on the step size of the integrator, the derivative dX_a/dt would be greater, if the integrator reduces the step size. This is not physically meaningful. The step size chosen by the integrator depends on the tolerances, but the actual speeds cannot be affected by this apart from rounding errors.
That makes sense! So instead of that I will give a constant value for GxdeltaT which is the total mass of air in the chamber at any instance if pressure inside the chamber is maintained. Thank you!!

Sign in to comment.

Answer by James Tursa
on 14 Jun 2018

Based on your description, I would conclude that the deltat in the equation is simply the total amount of time that the mass flow rate has been taking place. If you start the simulation at time 0 and pass in t to your derivative routine, then you can simply use t in place of deltat in your MATLAB code.


Show 1 older comment
If G*deltat is the "total air mass" and G is the mass flow rate, then it still sounds to me like the deltat is simply the total time that the mass flow rate has been taking place. I.e., simply use t instead of deltat in your code.
if I use t then the differential equation will be a function of t as well. Is that what you are saying ?
Yes, that's what it looks like to me since that is what is needed to calculate the total air mass at time t.

Sign in to comment.