MathGroup Archive 1999

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

Search the Archive

RE: "Solve" or "FindRoot" in a module


Jung Sik Kong [kongj at bechtel.colorado.edu] wrote:

> I have following problems:
> -------------------------------------------------------------------
> 1. How do I extract a solution from the results of
>    Solve or FindRoot in a module
>
> 2. How can I use % in a Module.
> -------------------------------------------------------------------
>
> I know that I can use "Replace" to extract a solution from a
> result of "Solve" or "FindRoot".
> However, I do not know how do I extract a solution in a Module.
>
> Next is a part of my file.
> (I'd like to keep x as a local variable.)
>
> -----------------------------------------------
> In[1]=StandardDist = NormalDistribution[0,1];
> In[2]=CDFStandardDist[x_] := CDF[StandardDist, x]
> In[3]=aa[y_] := Module[ {x},
>          FindRoot[CDFStandardDist[x]==y,{x,0}] ]
>
>
> In[4]= Plot[aa[y],{y,0.0001,0.9999}]
> -----------------------------------------------
>
> To plot a graph, I need to assign a value to the function "aa".
> But I don't know how to do it.

Hi Jung!

I guess you don't have to use Module to do what you want -- since you're
always using the same CDFStandardDist. Try this:

In[1]:=
Clear[aa, bb];
bb[y_] := FindRoot[CDFStandardDist[x] == y, {x, 0}];
aa[y_] := x /. bb[y]
In[4]:=
Plot[aa[v], {v, 0.05, 0.95}]

Hope this helps,

Tomas Garza
Mexico City


  • Prev by Date: Physical constants and their evaluation
  • Next by Date: Version 4.0 - Importing TIF files
  • Previous by thread: Physical constants and their evaluation
  • Next by thread: Re: RE: "Solve" or "FindRoot" in a module