1
$\begingroup$

Scipy integration allows us to do ode integration one adaptive timestep at a time and do something to it. However, matlab ode needs us to specify a timespan , and determine the adaptive timestep within, but cannot do things within.

From scipy

ODE.set_initial_value(y0, tlist[0])
numoftimes = len(tlist)
for ii in range(1, numoftimes):
    # while loop up to tlist[ii]
    while ODE.t < tlist[ii]:
        t_prev = ODE.t
        y_prev = ODE.y            
        # integrate up to tlist[ii], one step at a time.
        ODE.integrate(tlist[ii], step=1)
        #do something to the output
        ...

However, in matlab, I failed to do this, mainly step=1 is not available. Which ODE solver in Matlab allows me to advance in just one timestep only

Attempt is to make the tspan extremely small in matlab ode suite. But this is then not adaptive. In some region the original ode timestep is very big (non-stiff), but at some regions the ode timestep is very small (stiff).

tlist = [0 tf]    
numoftimes = len(tlist)
for ii = 1:numoftimes
     # while loop up to tlist(ii)
     while t_prev < tlist(ii)
            t_prev = T(end,:)
            y_prev = Y(end,:)           
            # integrate up to tlist(ii), one step at a time.
            t    = [t_prev,t_prev+0.0000000000001];
            [T, Y] = ode45(dydt, t, y);
            #do something to the output
            ...
     end
end

This then is not good as I have, even if the ode45 does integrate with only 1 step 1. force the timestep to be fixed interval 2. time-consuming as in some non-stiff region the "original adaptive" timestep needs not be that small.

How can I solve this with matlab ode suite?

$\endgroup$
  • $\begingroup$ Can you explain what you are trying to accomplish with this? This seems like a case of meta.stackexchange.com/questions/66377/what-is-the-xy-problem, and you haven't answered this in your other question either. If I were to guess, you should use dense output functionality (mathworks.com/help/matlab/ref/ode45.html#inputarg_tspan), but I really can't tell. $\endgroup$ – Kirill Nov 29 '16 at 0:41
  • $\begingroup$ I am trying to do something to my output, which is then fed into the ode solver at one timestep later. I hope to do this at every adaptive timestep, which changes according to stiffness. $\endgroup$ – diff Nov 29 '16 at 1:17
  • $\begingroup$ If that's the case, I'd say it's probably not altogether correct to call what you have an "ODE". You can do this easily, though, whatever it is, by implementing the time-stepping yourself (it's quite easy for typical methods). $\endgroup$ – Kirill Nov 29 '16 at 1:30
  • $\begingroup$ but i can do this in scipy. I want to know how to do this in ode matlab suite. Also, the time-stepping from the ode solver is intended to reduce time for non-stiff region and increase accuracy for stiff-region. How can I implement adaptive time step myself? $\endgroup$ – diff Nov 29 '16 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.