Is someone able to explain to me exactly what the "odefun" called by the "ode45" ODE solver in MATLAB is supposed to do?
My understanding is that you represent an n-order ODE as a system of n first-order ODEs and that, somehow, from this system, you create the "odefun" which "ode45" uses. My understanding is also that "odefun" should output a column array of derivative values at an the input independent variable value and that the function takes in a column array of values (but I'm not sure what these are).
How do you actually represent the system of first-order ODEs in "odefun"?
Thanks in advance for your help.
Yes you have to represent n-order ODE as a system of n 1st-order ODEs.
ode45 uses your odefun.
The function definition for ode45 is:
where:
tspan: problem domain e.g[-10 10]. If you don't want a step-size picked by matlab you can do-10:0.1:10for a step-size of 0.1y_0: Initial conditions for the system. With n 1st-order ODEs,y_0should be numeric vector of size n. with specification for all of y'(0), y''(0), y'''(0) ... . Of course you will have a translation to 1st-order like y1 = y, y2 = y', y3 = y'', ... .option1, option2, ...: These are meant for odefun.with that the definition for odefun is:
Note:
y_0in ode45 vsy_nin odefun.y_nare the values at the nth discretization as they are computed by ode45. Andtis the current time (assuming ady/dtODE)What is expected of you in odefun?
Compute and return the right-hand side of the 1st-order ODEs. This is numeric vector of the same length as
y_n. In most cases, these are some function ofy_nExample: If you have
y' = 3 - option1 * yas your 1st-order ODE, then in odefun you return3 - option1 * y_n. In this casey_nis of size 1 as I am assuming a single 1st-order ODE.