       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>

```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:= GarpOk[{{1., 2.}, {2., 1.}}, {{1., 2.}, {2., 1.}}]
> Out= {{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:= GarpRand2[r1_, r2_] := Module[{x11, x12, x21, x22, xrand},
>   x11 = r1*m[]/p[[1, 1]];
>   x12 = (1 - r1)*m[]/p[[1, 2]];
>   x21 = r2*m[]/p[[2, 1]];
>   x22 = (1 - r2)*m[]/p[[2, 2]];
>   xrand = {{x11, x12}, {x21, x22}};
>   Min[Boole[Union[Flatten[GarpOk[p, xrand]]]]]
>   ]
>
> In:= GarpRand5[r1_, r2_] := Module[{x11, x12, x21, x22, xrand},
>   x11 = r1*m[]/p[[1, 1]];
>   x12 = (1 - r1)*m[]/p[[1, 2]];
>   x21 = r2*m[]/p[[2, 1]];
>   x22 = (1 - r2)*m[]/p[[2, 2]];
>   xrand = {{x11, x12}, {x21, x22}};
>   Boole[FreeQ[Union[GarpOk[p, xrand]], False]]
>   ]
>
> In:= Integrate[GarpRand2[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> Out= 0.888889
>
> In:= NIntegrate[GarpRand2[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> Out= 0.888889
>
> In:= Integrate[GarpRand5[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> Out= 0
>
> In:= NIntegrate[GarpRand5[x1, x2], {x1, 0, 1}, {x2, 0, 1}]
> During evaluation of In:= 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= 0.
>
> As a test I tried a brute force approach, which yielded similar results.
>
> In:= N[Plus @@
>    Table[GarpRand2[RandomReal[{0, 1}], RandomReal[{0, 1}]], {100000}]/
>   100000]
> Out= 0.88731
>
> In:= N[Plus @@
>    Table[GarpRand5[RandomReal[{0, 1}], RandomReal[{0, 1}]], {100000}]/
>   100000]
> Out= 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:= 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:= tClosure[m_] := Sign[MatrixPower[m, Length[m]]]
>
> In:= 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