ode45
2 views (last 30 days)
Show older comments
Hello,
When using ode45, I know I can specify the integrand as a function of time. For instance, dx/dt = cos(t) - x.
Is there a way to alternatively specify the integrand as a set of data points? For instance replace cos(t) with a set of data points that I load.
When I try doing this I'm getting an error. I think because of the internal time steps ode45 uses is different than the times steps in my data points. Changing the tspan input to match the time steps in my data points doesn't seem to make any difference in the internal time steps ode45 uses. Is there any way around this problem?
Thank you, Kevin
0 Comments
Accepted Answer
Jan
on 6 Jul 2011
5 Comments
Jan
on 7 Jul 2011
"Best" is relative. This depends on the dimension of the tabulated data and the demands for accuracy. E.g. using a table with 20 values for a full period of COS has a limited accuracy only. If further knowledge about the tabulated data is available, they should be used: e.g. if the values are differentiable, the 'linear' interpolation is better than 'nearest'. If the 2nd derivative is smooth also, 'cubic' will reply more accurate values. If the time points for the table can be choosen freely, using Tschebyschev polynoms for interpolation has the maximal accuracy over the complete interval.
For a sinusoid with 100 time points over a period I'd choose the cubic interpolation. If speed matters, 1000 time points and linear interpolation might be better. If speed really matters, extract the actual used 5 or 8 lines of code from the slow INTERP1 function to create a much faster version.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!