Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inverse of Interpolating Function?

615 views
Skip to first unread message

gonzorascal

unread,
Jul 20, 2011, 6:34:25 AM7/20/11
to
Hello All,

I am working with an Interpolating Function of an oscillating solution (time series) to a differential equation. I am trying to find the period and pulse width of the oscillation. To do this I would like to have an inverse of my function y[t] (so I would have t[y]). I realize this function would be multivalued (that's what I want to find the period). I am not having success using Mathematica's InverseFunction[] or Reduce[] commands. Does anyone have any experience or suggestions with this sort of thing (either finding Inverse Interpolating Functions or another method for period and pulse width)? Thank you.

-GR

Gary Wardall

unread,
Jul 21, 2011, 5:48:33 AM7/21/11
to
On Jul 20, 5:34=C2 am, gonzorascal <dj...@duke.edu> wrote:
> Hello All,
>
> I am working with an Interpolating Function of an oscillating solution (time series) to a differential equation. I am trying to find the period and pulse width of the oscillation. To do this I would like to have an inverse of my function y[t] (so I would have t[y]). I realize this function would be multivalued (that's what I want to find the period). =C2 I am not having success using Mathematica's InverseFunction[] or Reduce[] commands. Does anyone have any experience or suggestions with this sort of thing (either finding Inverse Interpolating Functions or another method for period and pulse width)? Thank you.
>
> -GR

gonzorascal,

First make sure the function you wish to have an inverse function is a
function that has an inverse function. A quick visual test is the
Horizontal Test for Inverse Functions. If any horizontal line
intersects the graph twice or more then the inverse is NOT an inverse
function. Graph the function you wish to create an inverse function
for. If it fails the horizontal test you may have ti restrict your
function like is done in Trigonometry. If it passes try something like
in my example.


points = {{0, -1}, {1, 1}, {2, 3}, {3, 4}, {4, 6}, {5, 10}};=E2=80=A8ifun=
Interpolation[points]
Does the function pass the Horizontal Test?

Plot[ifun[x], {x, 0, 5}]

It does. Define:

invifun[x_] := FindRoot[ifun[y] == x, {y, 0, 5}][[1]][[2]]

Note that:

ifun[invifun[4]]

is 4.

and

invifun[ifun[3]]

is 3.

and look at the sketch.

Plot[{invifun[x], ifun[x], x}, {x, 0, 5}, PlotRange -> {0, 5},
AspectRatio -> Automatic]

We have an inverse function.

I hope this will help.

Good Luck

Gary Wardall

Jay Bee

unread,
Jul 21, 2011, 6:54:37 AM7/21/11
to

So, when you will find out the period, compute sufficient number of
points with the help of this interpolation function, e.g., as a
Table[], change coordinates, and interpolate again... Of course, if
you know exact formula, worth using it...

Oliver Ruebenkoenig

unread,
Jul 21, 2011, 7:24:34 AM7/21/11
to
On Thu, 21 Jul 2011, Gary Wardall wrote:

> On Jul 20, 5:34=C2 am, gonzorascal <dj...@duke.edu> wrote:
>> Hello All,
>>

>> I am working with an Interpolating Function of an oscillating solution (time series) to a differential equation. I am trying to find the period and pulse width of the oscillation. To do this I would like to have an inverse of my function y[t] (so I would have t[y]). I realize this function would be multivalued (that's what I want to find the period). =C2 I am not having success using Mathematica's InverseFunction[] or Reduce[] commands. Does anyone have any experience or suggestions with this sort of thing (either finding Inverse Interpolating Functions or another method for period and pulse width)? Thank you.
>>
>> -GR
>

You could also use NDSolve for that - that advantage would be that it will
generate an interpolation function

init = x /. FindRoot[ifun[x] == 0, {x, 0, 1}]

inf = t /.
First[NDSolve[{t'[a] == 1/(ifun'[t[a]]), t[0] == init},
t, {a, 0, 5}]]

Plot[{inf[x], ifun[x], x}, {x, 0, 5}, PlotRange -> {0, 5},
AspectRatio -> Automatic]

Oliver

Daniel Lichtblau

unread,
Jul 21, 2011, 9:07:11 PM7/21/11
to
On 07/20/2011 05:31 AM, gonzorascal wrote:
> Hello All,
>
> I am working with an Interpolating Function of an oscillating solution (time series) to a differential equation. I am trying to find the period and pulse width of the oscillation. To do this I would like to have an inverse of my function y[t] (so I would have t[y]). I realize this function would be multivalued (that's what I want to find the period). I am not having success using Mathematica's InverseFunction[] or Reduce[] commands. Does anyone have any experience or suggestions with this sort of thing (either finding Inverse Interpolating Functions or another method for period and pulse width)? Thank you.
>
> -GR
>

Here is an approach that might be suitable, at least if you can sample
from a fairly large number of periods.

(1) Sample your function in equal intervals.

(2) Take the Fourier transform.

(3) Find the largest frequency, not counting the first (DC) component.

(4) ue that to estimate the period.

Here is an example. We'll use a reference function that is a simple
sinusoid.

y[t] /. First[
DSolve[{y''[t] == -2*y[t], y[0] == 0, y'[0] == 1}, y[t], t]]

Out[1500]= Sin[Sqrt[2] t]/Sqrt[2]

The period is Sqrt[2]*Pi, or around 4.44288

We will now obtain this as an InterpolatingFunction from NDSolve, add a
DC component, sample at intervals, and add some random noise.

soln = y[t] /.
First[NDSolve[{y''[t] == -2*y[t], y[0] == 0, y'[0] == 1},
y[t], {t, 0, 150}]]

separation = .1;
vals = Table[soln + 3, {t, 0., 150., separation}];
vals = vals + RandomReal[{-.1, .1}, Length[vals]];

ft = Abs[Fourier[vals]];

mainfreq = Position[Rest[ft], Max[Rest[ft]]][[1, 1]]
Out[1563]= 34

Here is the period estimate.

In[1564]:= N[Length[vals]/mainfreq]*separation
Out[1564]= 4.41471

So this agrees with the period of the unperturbed signal to 2+ decimal
places.

A related approach may be found at

Documentation Center > Fourier > Applications > Frequency Identification

Daniel Lichtblau
Wolfram Research

Gary Wardall

unread,
Jul 21, 2011, 9:14:26 PM7/21/11
to
Yes, that is so. I kind of thought that's what GR should do,

Gary

On Thu, Jul 21, 2011 at 5:17 AM, Oliver Ruebenkoenig
<rueb...@wolfram.com>wrote:

> On Thu, 21 Jul 2011, Gary Wardall wrote:
>

> On Jul 20, 5:34 am, gonzorascal <dj...@duke.edu> wrote:
>>
>>> Hello All,
>>>
>>> I am working with an Interpolating Function of an oscillating solution
>>> (time series) to a differential equation. I am trying to find the period
>>> and pulse width of the oscillation. To do this I would like to have an
>>> inverse of my function y[t] (so I would have t[y]). I realize this function
>>> would be multivalued (that's what I want to find the period). I am not
>>> having success using Mathematica's InverseFunction[] or Reduce[] commands.
>>> Does anyone have any experience or suggestions with this sort of thing
>>> (either finding Inverse Interpolating Functions or another method for period
>>> and pulse width)? Thank you.
>>>
>>> -GR
>>>
>>

>> gonzorascal,
>>
>> First make sure the function you wish to have an inverse function is a
>> function that has an inverse function. A quick visual test is the
>> Horizontal Test for Inverse Functions. If any horizontal line
>> intersects the graph twice or more then the inverse is NOT an inverse
>> function. Graph the function you wish to create an inverse function
>> for. If it fails the horizontal test you may have ti restrict your
>> function like is done in Trigonometry. If it passes try something like
>> in my example.
>>
>>

>> points = {{0, -1}, {1, 1}, {2, 3}, {3, 4}, {4, 6}, {5, 10}}; ifun=

0 new messages