MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: motion-path and spline-arc-length

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


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


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:

NInverse[#^2 &, {2, 4}, {y, 1, 9}]

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


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:

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

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


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


and tries


{{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

Carl Woll
Physics Dept
U of Washington

"Pier" <piviere at> wrote in message
news:9fq1iu$qam$1 at
> 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