MathGroup Archive 2008

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

Search the Archive

Re: NIntegrate Confusion

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90610] Re: [mg90605] NIntegrate Confusion
  • From: DrMajorBob <drmajorbob at att.net>
  • Date: Wed, 16 Jul 2008 06:28:01 -0400 (EDT)
  • References: <5875509.1216120736290.JavaMail.root@m08>
  • Reply-to: drmajorbob at longhorns.com

The code doesn't run here because m and p have no values.

It's poor form, too, for functions (GarpRand2, GarpRand5) to depend on  
globals -- even if they DID have values.

Bobby

On Tue, 15 Jul 2008 05:49:38 -0500, Timothy Beatty  
<timothy.beatty at gmail.com> wrote:

> Hi,
>
> I'm using Mathematica 6.0 on OS X 10.5.4
>
> I have a function that returns a matrix of "True" and "False" values.
> Any "False" value indicates a failed test.
>
> For example:
> In[7]:= GarpOk[{{1., 2.}, {2., 1.}}, {{1., 2.}, {2., 1.}}]
> Out[7]= {{True, False}, {False, True}}
>
> Now I'd like to use NIntegrate to compute the area of these tests, I
> wrote two versions of a functions which differ only in the way they
> return a value of zero or one, GarpRand2 and GarpRand5.  However they
> produce different results when used with NIntegrate (and Integrate).
>
> In[8]:= GarpRand2[r1_, r2_] := Module[{x11, x12, x21, x22, xrand},
>   x11 = r1*m[[1]]/p[[1, 1]];
>   x12 = (1 - r1)*m[[1]]/p[[1, 2]];
>   x21 = r2*m[[2]]/p[[2, 1]];
>   x22 = (1 - r2)*m[[2]]/p[[2, 2]];
>   xrand = {{x11, x12}, {x21, x22}};
>   Min[Boole[Union[Flatten[GarpOk[p, xrand]]]]]
>   ]
>
> In[9]:= GarpRand5[r1_, r2_] := Module[{x11, x12, x21, x22, xrand},
>   x11 = r1*m[[1]]/p[[1, 1]];
>   x12 = (1 - r1)*m[[1]]/p[[1, 2]];
>   x21 = r2*m[[2]]/p[[2, 1]];
>   x22 = (1 - r2)*m[[2]]/p[[2, 2]];
>   xrand = {{x11, x12}, {x21, x22}};
>   Boole[FreeQ[Union[GarpOk[p, xrand]], False]]
>   ]
>
> In[10]:= Integrate[GarpRand2[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> Out[10]= 0.888889
>
> In[11]:= NIntegrate[GarpRand2[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> Out[11]= 0.888889
>
> In[12]:= Integrate[GarpRand5[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> Out[12]= 0
>
> In[13]:= NIntegrate[GarpRand5[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> During evaluation of In[13]:= NIntegrate::ncvb: NIntegrate failed to
> converge to prescribed \
> accuracy after 18 recursive bisections in x1 near {x1,x2} = \
> {0.666667,0.844124}. NIntegrate obtained 0.` and 0.` for the integral \
> and error estimates. >>
> Out[13]= 0.
>
> As a test I tried a brute force approach, which yielded similar results.
>
> In[14]:= N[Plus @@
>    Table[GarpRand2[RandomReal[{0, 1}], RandomReal[{0, 1}]], {100000}]/
>   100000]
> Out[14]= 0.88731
>
> In[15]:= N[Plus @@
>    Table[GarpRand5[RandomReal[{0, 1}], RandomReal[{0, 1}]], {100000}]/
>   100000]
> Out[15]= 0.8909
>
> I have no idea why these two functions, which to my very untrained eye
> do the same thing, obtain different results with Integrate and
> NIntegrate.  Any help would be very much appreciated.
>
> Tim
>
>
> P.S. For completeness I've attached the GarpOk function below
>
> In[1]:= rdMatrix[p_, x_] := Module[{i, j, n},
>   n = Length[x];
>   Boole /@
>    Table[p[[i]].x[[i]] >= p[[i]].x[[j]], {i, 1, n}, {j, 1, n}]
>   ]
>
> In[2]:= tClosure[m_] := Sign[MatrixPower[m, Length[m]]]
>
> In[3]:= GarpOk[p_, x_] := Module[{i, j, n, m},
>   n = Length[x];
>   m = tClosure[rdMatrix[p, x]];
>   Table[If[m[[i, j]] == 1 && ( p[[j]] . x[[j]] > p[[j]] . x[[i]]),
>     False, True], {j, 1, n}, {i, 1, n}]
>   ]
>
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: Re: running multiple mathkernel's
  • Next by Date: Conditional Table Formatting
  • Previous by thread: NIntegrate Confusion
  • Next by thread: genetic algorithms