# Numerically calculating derivatives in the ODE solvers using the matlab time step size, is it a good idea, and if it's ok what is the best way to do it?

2 views (last 30 days)
Richard Crozier on 18 Mar 2011
Hello,
I am thinking of creating a system of differential equations to be solved using the Matlab ode solvers, the right hand side of which will be calculated by dividing a value calculated in the function by the last time step chosen by matlab. I would like to know if this is likely to work, or if there are reasons it is not a good idea.
My first problem is actually obtaining the current step size, but I'm sure I can achieve this using persistent variables, perhaps updating the last time value chosen in a global variable using the OutputFcn option, when the final step choice will be known. If someone has a better way of doing this, I would also like to know this.
I would then calculate my quantities of interest and calculate an approximation their derivatives using something like:
global last_t
% calculate the new values of the x variables
x_new = getnewvaluesofx(t, x, etc, blah, blah);
deltat = t - last_t;
dx = (x_new - x) ./ deltat;
In general I will expect the variables to be fairly well behaved
To be more specific about what I am doing, I plan to use a matlab finite element toolbox (FEASOR) to do some transient thermal simulations. I will calculate the nodal temperatures in a mesh and their change in time at each time step. There are other things being simulated as well, some of which are dependent on the temperature. All of the other things have algabraic solutions though, and I have solved them fine without the thermal stuff.

### Categories

Find more on Ordinary Differential Equations in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by