Using interp1 to find values of parabolic data.

3 views (last 30 days)
Don  Isiko
Don Isiko on 22 Feb 2012
Hi ^^,
I've recently been working with matlabs ODE commands and one thing I would like to do is use interpolation to find a value for time when my y is equal to zero. This is more difficult since I'm aware interp1 works well with linearly spaced numbers; finding y would be straightforward since t can be made linear and is ever increasing. But if I wish to find a time for a given y, interp1 isn't as accurate.
Here's my coding:
tf=interp1(y,t,yguess)
While normally to get an accurate estimate of y you would do
t=[0:0.001:24]
[t,y]=ode('funcexmp',t,input)
yf=interp1(t,y,tguess)
Anyone happen to know how I could reverse this to find time reliably? Or is the stability/robustness of interp1 just that bad?
Thanks for the help in advance!!

Answers (2)

Sean de Wolski
Sean de Wolski on 22 Feb 2012
One way would be to use fzero with interp1 as the function (probably inside a wrapper).

owr
owr on 22 Feb 2012
It's been awhile since Ive done this, but I think you can get what you are looking for directly from the ode solvers using "event location" - no interpolation after the fact is necessary. Basically you can tell the ode solver to watch and record when zero crossings of functions of your solution occur. For your problem, it's just when y == 0, so its quite simple.
Check out the bouncing ball example (ballode) in the docs:
You wont be setting the condition to be terminal.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by