Re: Re: FindRoot output format
- To: mathgroup at smc.vnet.net
- Subject: [mg3463] Re: [mg3453] Re: FindRoot output format
- From: Elias Saab <mathes at esaab.math.missouri.edu>
- Date: Sat, 9 Mar 1996 00:59:35 -0500
- Sender: owner-wri-mathgroup at wolfram.com
If one only needs to plot the inverse of f[x], the following code will do: ParametricPlot[{f[x],x]},{x,.5,.8}] On Fri, 8 Mar 1996, Ian Collier wrote: > In article <4hjana$gph at dragonfly.wolfram.com>, "Nicolo' Manaresi" > <manaresi at iis.ee.ethz.ch> wrote: > > > Hi, > > I would like to define the inverse function of > > f[x_] = 3*x*(1 - x^2)^(1/2) + (1 + 2 x^2)*ArcCos[-x] > > (defined for x in [-1,1]). > > I defined then: > > finv[y_] = FindRoot[ f[x] == y, {x,0}] > > > > I woul like to plot it and use finv in more complex expressions, but I have > > some problem > > since evaluation of finv yeld something in the form {x -> number} > > e.g.: > > > finv[0.5] > > > {x -> -0.363331} > > So for example > > > Plot[finv[y],{y,0.5,0.8}] > > results in errors of this kind: > > Plot::plnr: CompiledFunction[{y}, finv[y], -CompiledCode-][y] > > is not a machine-size real number at y = 0.5 > > > > Does anybody knows how to work arond this kind of output format? > > Does anybody know how could I invert f with another Mathematica's instruction, > > without this problem? > > > > Thank you, > > Nicolo' Manaresi > > The result from FindRoot is coming back as a replacement rule. > (Something of the form {x -> -0.363331}.) > > All you need to do is to use ReplaceAll ( "/." in infix notation) > to substitute the answer. The following will work. > > In[15]:= > f[x_] = 3*x*(1 - x^2)^(1/2) + (1 + 2 x^2)*ArcCos[-x] > Out[15]= > 2 2 > 3 x Sqrt[1 - x ] + (1 + 2 x ) ArcCos[-x] > > In[16]:= > finv[y_] := FindRoot[ f[x] == y, {x,0}] > > In[17]:= > finv[0.5] > Out[17]= > {x -> -0.363331} > > In[18]:= > Plot[x /. finv[y], {y,0.5,0.8}] > > Out[18]= > -Graphics- > > Section 2.4 of "Mathematica, A Sytem for Doing Mathematics by > Computer", Transformation Rules and Definitions, explains this > in some more detail. > > I hope this helps. > > --Ian > > ----------------------------------------------------------- > Ian Collier > Wolfram Research, Inc. > ----------------------------------------------------------- > tel:(217) 398-0700 fax:(217) 398-0747 ianc at wolfram.com > Wolfram Research Home Page: http://www.wolfram.com/ > ----------------------------------------------------------- > ==== [MESSAGE SEPARATOR] ====