Re: FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg131651] Re: FindRoot
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Sun, 15 Sep 2013 07:10:07 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <20130914100359.B62286A32@smc.vnet.net>
In Part I, n -- as defined in the module -- is given a transient value by the expression n /. FindRoot[powerEST - (1 - \[Beta]), {n, 40}] Use Print statements to track what occurs. f[n_, p1_, p2_] := Sqrt[2 n] (ArcSin@Sqrt[p1 - 1/(2 n)] - ArcSin@Sqrt[p2 + 1/(2 n)]); myModule1[=E1_, =E2_] := Module[{ A = ConstantArray["", {9, 9}], n, powerEST, p1 = 0.2, p2 = 0.1, index1, index2, val}, aIf[p1 > p2, powerEST = SurvivalFunction[ NormalDistribution[f[n, 0.2, 0.1], 1], Quantile[NormalDistribution[], 1 - =E1]]; Print["array indices = ", {index1 = IntegerPart[10 (p1 - 0.1)], index2 = IntegerPart[10 p2]}]; Print[ val = Ceiling[ n /. FindRoot[powerEST - (1 - =E2), {n, 40}, EvaluationMonitor :> Print["n = ", n]]]]]; Print["But n was not set: n = ", n]; A[[index1, index2]] = val]; myModule1[0.05,0.05] array indices = {1,1} n = 40. n = 154.16 n = 226.772 n = 271.381 n = 287.216 n = 288.886 n = 288.903 n = 288.903 289 But n was not set: n = n$339 289 Bob Hanlon On Sat, Sep 14, 2013 at 6:03 AM, <bruce.colletti at gmail.com> wrote: > Re 9.0.1 under Windows 7. > > The code below is extracted from another source. > > Part I below returns 289 even though n is never given a value. Why does > the module return a value and in particular, what does 289 mean? > > Part II doesn't return a value (as expected). I don't see why Part I > returns a value but not Part II. > > Thanks. > > Bruce > > > In[1]:= > (* Part I *) > f[n_,p1_,p2_]:=Sqrt[2n](ArcSin@Sqrt[p1-1/(2n)]-ArcSin@Sqrt[p2+1/(2n)]); > > > myModule1[\[Alpha]_,\[Beta]_]:=Module[{A=ConstantArray["",{9,9}],n,po= werEST,p1=0.2,p2=0.1}, > If[ > p1>p2, > > powerEST=SurvivalFunction[NormalDistribution[f[n,0.2,0.1],1],Quantile[N= ormalDistribution[],1-\[Alpha]]]; > > > A[[IntegerPart[10(p1-0.1)],IntegerPart[10p2]]]=Ceiling[n/.FindRoot[powe= rEST-(1-\[Beta]),{n,40}]] > ] > ]; > > myModule1[0.05,0.05] > Out[3]= 289 > In[4]:= > (* Part II *) > myModule2[\[Alpha]_,\[Beta]_]:=Module[{A=ConstantArray["",{9,9}],n}, > > SurvivalFunction[NormalDistribution[f[n,0.2,0.1],1],Quantile[NormalDistri= bution[],1-\[Alpha]]] > ]; > > myModule2[0.05,0.05] > Out[5]= 1/2 Erfc[(1.64485 -Sqrt[2] Sqrt[n$272] (ArcSin[Sqrt[0.2 -1/(2 > n$272)]]-ArcSin[Sqrt[0.1 +1/(2 n$272)]]))/Sqrt[2]] > >
- References:
- FindRoot
- From: bruce.colletti@gmail.com
- FindRoot