Borrar filtros
Borrar filtros

ode45

2 visualizaciones (últimos 30 días)
Kevin Bachovchin
Kevin Bachovchin el 6 de Jul. de 2011
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

Respuesta aceptada

Jan
Jan el 6 de Jul. de 2011
This sounds like a job for TRAPZ.
  5 comentarios
Kevin Bachovchin
Kevin Bachovchin el 7 de Jul. de 2011
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 el 7 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by