-1
$\begingroup$

[t,y] = odeXX(odefun,tspan,y0)

I have a solver odeXX, and the tspan = [0 0.0001]. It seems that for any ode solver in MATLAB, they integrate by breaking tspan into multiple steps (some adaptive like ode45 and some non-adaptive). But I am looking for the most primitive one--just integrate from 0 to 0.0001 in one step. Which ode solvers allow me to do this and how to specify this?

$\endgroup$
  • $\begingroup$ Possible duplicate: stackoverflow.com/questions/2549238/… $\endgroup$ – yohbs Nov 7 '16 at 2:49
  • 1
    $\begingroup$ What's the difference? You're just making a constant step instead of steps. Run ode45 with a constant step that's equal to your end time and you're done. $\endgroup$ – yohbs Nov 7 '16 at 4:55
  • 1
    $\begingroup$ From messing around (MATLAB R2014b) it looks like you can get one step on e.g. ODE45 by setting RelTol,AbsTol,InitialStep and MaxStep large enough. This results in 7 function evaluations $\endgroup$ – Steve Nov 7 '16 at 11:24
  • 2
    $\begingroup$ Why do you want to do this?. $\endgroup$ – David Ketcheson Nov 7 '16 at 16:04
  • 2
    $\begingroup$ But why do you want to check it after one step, rather than checking it after a fixed time interval? I believe that if you explain what you really want to do, then there will be a more useful way to accomplish it. $\endgroup$ – David Ketcheson Nov 9 '16 at 5:51
2
$\begingroup$

Are you asking for a method that solves $x'(t)=f(t,x(t))$, $x(0)=x_{0}$ with only one evaluation of $f$ or are you willing to evaluate $f$ at multiple points? How accurate a solution do you need?

Although MATLAB's built-in solvers with adaptive step sizes won't do this for you, it's trivial to implement your own method. e.g. Euler's method is simply $x_{1}=x_{0}+hf(t_{0},x_{0})$. Implementing RK4 isn't much harder.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ or take this one... cn.mathworks.com/matlabcentral/fileexchange/… $\endgroup$ – Jan Nov 7 '16 at 16:11
  • $\begingroup$ i want to evaluate in one step as i want to check the result after integration in one step and do things according to that result. So I have to manually use step = 1. $\endgroup$ – diff Nov 7 '16 at 23:09
  • $\begingroup$ If you're interested in stopping the simulation as soon as the system reaches a particular state (e.g. when x(t)=0), MATLAB's ODE solvers have a built-in feature for "ODE Event Location" that does this. $\endgroup$ – Brian Borchers Nov 7 '16 at 23:29
  • $\begingroup$ @Brian Borchers not only that. I want to do multiple things to the output at each "step" and update the ODE.y (as in scipy) and carry on the ODE.integrate(..., step=1) again. So I cannot afford to do this in ode45, which takes multiple steps so it is time-consuming. $\endgroup$ – diff Nov 8 '16 at 6:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.