MATLAB: How to solve an ODE defined by both a function and data

MATLAB

I am trying to solve an ODE with 'ode45', but my ODE only has a functional form for some of the 't' bounds. For some of the other 't' bounds, I only have data describing the ODE.
How can I solve this ODE with 'ode45'?

Best Answer

One potential solution involves the use of interpolation. See the attached m files for a worked example.
The general workflow looks like the following:
1. Define a new function 'odefun',
2. In 'odefun', add a check to see if you have a defined function for the input 't' or not
- If you do, then evaluate the function at the input 't' and 'y'
- If you do not, then use an interpolation function (like 'interp1') to evaluate the input 't' and 'y' using the rest of your data.
3. In 'ode45', pass in your defined 'odefun'