ode45
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2011-7-6
5 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!