Re: How to invert a function
- To: mathgroup at smc.vnet.net
- Subject: [mg81146] Re: How to invert a function
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 14 Sep 2007 03:30:45 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <fcb3f3$ff9$1@smc.vnet.net>
Teodoro wrote: > this is my first post ro the Mathematica group, so, please be patient ... > The problem I'm trying to solve is a little bit more complex, but > anyway I was able to reproduce the unwanted behaviour using a "toy" example. > As far as I understand the fragment of code > > m = 7.984136668700428`*^-14; p = 38.64734299516908`; n = > 9.185777`*^-7; q = 7.729468599033817`; r = -9.18579746734159`*^-7; > f[y_] = m Exp[p y]; > g[x_] := Solve[f[y] == x, y] > h[x_] := y /. g[x] > > allows me to get y as a function of x. To check that h[x] is indeed > the inverse of f[y] (you already know the solution !) one can run > > Evaluate[f[h[z]]] > Evaluate[h[f[z]]] > > for any value of z you get again z: > > z -> h[z] -> f[h[z]=z > z -> f[z] -> h[f[z]=z > > or > > Plot[Evaluate[h[x]], {x, 1, 20}, PlotRange -> {Full}] > > and get a straight line. > However, when I try to invert > > f[y_] = m Exp[p y]+n Exp[q y]+r > > I get some result, but the result is WRONG ! > In another system I get the correct behaviour, even with more complex > functions ... > I can guess that somewhere in the answers I can get the one I need, > but the Forum is so immense ! Few random comments. Using /inexact/ numbers (i.e. floating-point numbers, also called machine-size precision numbers) with *Solve* is a very bad idea for *Solve* has been designed to seek /symbolic/ (i.e. exact) solutions. To express a symbolic inverse, use *InverseFunction* (c.f. a recent thread on this subject). To get the numerical inverse of a function at a point, you may use *FindRoot* as explained in the documentation center at ref/FindRoot -> Applications -> "Computing Inverse Function." Depending on what your initial function is made of, you should check the documentation center at guide/InverseFunctions to see whether an exact symbolic form already exists (i.e. is provided by Mathematica). Computing the symbolic inverse of a function every time you want to evaluate it at a point is a waste of time and resources. Compute the inverse first (that is simplify the expression first, perhaps using some assumptions on the parameters, compute the inverse with *Solve* or *Reduce*, check the conditions, and simplify the solution, finally give a name to this solution). Regards, -- Jean-Marc