ode45

2 次查看(过去 30 天)
Kevin Bachovchin
Kevin Bachovchin 2011-7-6
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

采纳的回答

Jan
Jan 2011-7-6
This sounds like a job for TRAPZ.
  5 个评论
Kevin Bachovchin
Kevin Bachovchin 2011-7-7
When using the interp1 function, are you familiar with what the different options do? The help file for interp1 doesn't give much detail on that. The options 'nearest' and 'linear' seem pretty self-explanatory, but it's not clear to me what the differences between 'spline','pchip','cubic', and 'vcubic' are.
If I'm using data that is a sinusoid or close to a sinuosoid, what do you think the best option to use is?
Jan
Jan 2011-7-7
"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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by