Re: RE: "Solve" or "FindRoot" in a module
- To: mathgroup at smc.vnet.net
- Subject: [mg18151] Re: [mg18109] RE: [mg18033] "Solve" or "FindRoot" in a module
- From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
- Date: Sat, 19 Jun 1999 23:54:22 -0400
- Sender: owner-wri-mathgroup at wolfram.com
It is true that in general Module is not needed, but in certain (admittedly
very rare) situations you can get unexpected results. For example, first
define
x:=Plot[t^2,{t,-1,1}]
and then evaluate your code to see what I mean.
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp
----------
>From: "Tomas Garza" <tgarza at mail.internet.com.mx>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg18151] [mg18109] RE: [mg18033] "Solve" or "FindRoot" in a module
>Date: Fri, Jun 18, 1999, 1:26 AM
>
> 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
>