Asked by Indu Muthancheri
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.

[t,y]=ode45(@xx,tspan,yo); %% in function xx function dydt=xx(t,y) dydt=zeros(3,1); dydt(1)=A*deltat; %deltat is the time step during that iteration dydt(2)=f(y(1),y(2),....) dydt(3)=f(y(1),y(2)....) end

Thank you so much in advance for the help!

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.

Jan
on 14 Jun 2018

Indu Muthancheri
on 14 Jun 2018

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.

James Tursa
on 14 Jun 2018

Indu Muthancheri
on 14 Jun 2018

James Tursa
on 14 Jun 2018

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## James Tursa (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/405707-in-ode-solver-how-to-use-the-time-step-of-each-iteration-within-the-differential-equation#comment_578797

Your differential equation may contain something like "dy/dt" etc when written out, but that dt is

NOTthe time step used by the numerical integrator! This is simply derivative notation. What is the DE you are trying to solve?## Indu Muthancheri (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/405707-in-ode-solver-how-to-use-the-time-step-of-each-iteration-within-the-differential-equation#comment_578856

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.