       Re: inverse function computation

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

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

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., 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 softhome.net> wrote in message
news:9tlau9\$nve\$1 at smc.vnet.net...
> 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
know
> 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