Re: motion-path and spline-arc-length

• To: mathgroup at smc.vnet.net
• Subject: [mg29277] Re: motion-path and spline-arc-length
• From: "Carl K. Woll" <carlw at u.washington.edu>
• Date: Sat, 9 Jun 2001 03:09:05 -0400 (EDT)
• Organization: University of Washington
• References: <9fq1iu\$qam\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Pier,

Recently, David Park asked essentially the same question, and you can see
their solution on the thread Inverse Interpolating Functions. As an
alternative to their approach, I am proposing a completely different
solution (which naturally I like better).

The basic idea is to turn your question into a differential equation.
Mathematica's NDSolve function numerically solves differential equations,
and returns InterpolatingFunctions, which is just what the doctor ordered.
In your example we have the following problem:

Given y-f[x[y]]==0, what is x?

Simply differentiate with respect to the dependent variable, which in this
case is y, yielding

1-f'[x[y]]x'[y]==0.

This is a differential equation for the function x[y], so we can use
NDSolve. The only thing missing is an initial condition. Of course, if the
inverse of the function f is multivalued, there will be multiple possible
initial conditions. So, we need to supply an initial condition. A function
which takes these ideas and puts them together follows:

NInverse[f_, {x0_, y0_}, {y_, min_, max_}, opts___?OptionQ] :=
NDSolve[{1 - f'[x[y]]x'[y] == 0, x[y0] == x0}, x, {y, min, max}, opts]

In the above function, f should be a pure function, although this is not
absolutely necessary. The point {x0,y0} is the initial condition, and the
function f should satisfy f[x0]==y0. The "dependent variable" y will range
from min to max. The options should be those expected by NDSolve. Obviously,
a little bit more work can be done to make the function a bit more bullet
proof. Typically, NDSolve will yield an accuracy (precision) of 6 decimal
places, so if more accuracy is desired, a more accurate PrecisionGoal and
AccuracyGoal can be given as options to the function NInverse.

As a trivial example, suppose one wanted to invert the equation y=x^2. In
this case f is #^2&. So, we would use NInverse as follows:

In[52]:=
NInverse[#^2 &, {2, 4}, {y, 1, 9}]

Out[52]=
{{x -> InterpolatingFunction[{{1., 9.}}, <>]}}

In[53]:=
Plot[%[[1,1,2]][t]-Sqrt[t],{t,1,9},PlotRange->All]

I have deleted the Plot output, but it shows that the difference between the
solution and Sqrt[t] is smaller than 3 10^-5. If more precision were
desired, then one could try:

In[54]:=
NInverse[#^2 &, {2, 4}, {y, 1, 9}, AccuracyGoal -> 10,
PrecisionGoal -> 10]

Out[54]=
{{x -> InterpolatingFunction[{{1., 9.}}, <>]}}

In[55]:=
Plot[%[[1,1,2]][t]-Sqrt[t],{t,1,9},PlotRange->All]

Here the difference is less than 5 10^-9. NInverse will work fine with
InterpolatingFunctions. For example, if one sets

f=FunctionInterpolation[x^2,{x,1,4}];

and tries

In[62]:=
NInverse[f,{2,4},{y,1,9},AccuracyGoal->10,PrecisionGoal->10]

Out[62]=
{{x -> InterpolatingFunction[{{1., 9.}}, <>]}}

You get back the same InterpolatingFunction as before.

As a side note, a package that I wrote and posted a while ago defining a
function called ImplicitSolve will take any set of N equations in N+1
unknowns, and return interpolating functions for N of the unknowns in terms
of the final unknown. The function NInverse is just a simplified version of
ImplicitSolve.

Carl Woll
Physics Dept
U of Washington

"Pier" <piviere at libero.it> wrote in message
news:9fq1iu\$qam\$1 at smc.vnet.net...
> Hi
>     I'm developping an animation software ...
> I've a spline (3rd degree) say Sp(t)
> well i would like to know if i can find a function that calculates
> the parameter t, given the distance travelled s=Sp(t).
> Something related to Arc-length.
>
> Thank in advance to all help me.    Bye, Pier
>
>

```

• Prev by Date: Re: Control ListContourPlot and LabelContourLines
• Next by Date: Delphi
• Previous by thread: motion-path and spline-arc-length
• Next by thread: Fourth degree polynomial