MathGroup Archive 2001

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

Search the Archive

Re: inverse function computation

  • To: mathgroup at
  • Subject: [mg31702] Re: inverse function computation
  • From: "Carl K. Woll" <carlw at>
  • Date: Tue, 27 Nov 2001 02:47:55 -0500 (EST)
  • Approved: Steven M. Christensen <>, Moderator
  • Organization: University of Washington
  • References: <9tlau9$nve$>
  • Sender: owner-wri-mathgroup at

Hi Margot,

One way to compute the inverse of a function is to cast the problem as a
differential equation which you can then hand off to the function NDSolve.
I've mentioned this idea in the past, and here is a summary.

The basic idea is to turn your question into a differential equation.
Mathematica's NDSolve function numerically solves differential equations,
and returns InterpolatingFunctions:

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., 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.

In your example we have f[x_]=x+.2 Sin[x], so the pure function would be
f=#+.2 Sin[#]&, and we would use NInverse as follows:

NInverse[#+.2 Sin[#]&,{0,0},{y,0,1}]

The output would be an interpolating function over the range {0,1} giving
the values of the inverse function f^(-1).
An interpolating function has some nice advantages over an approach using
FnidRoot, since it should be faster, and the resulting function can be both
differentiated and integrated.

Carl Woll
Physics Dept
U of Washington

"Margot" <gosia_sz at> wrote in message
news:9tlau9$nve$1 at
> Hello,
> I'd like to do the following manipulation.
> Let f be a homeomorphism (known explicitly).
> I want Mathematica to compute its inverse f^{-1} and to use it
> for further computations and plots.
> I'm assuming here that f^{-1} is not explicit (take f(x)=x+0.2Sin[x] for
> instance).
> I'm not sure that Mathematica has an already built-in function; do you
> any simple algorithm?
> Many thanks

  • Prev by Date: Re: Linux Font Problem
  • Next by Date: OOP Revisited
  • Previous by thread: Re: inverse function computation
  • Next by thread: printing in mathematica