MathGroup Archive 2003

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

Search the Archive

Re: Problem with NIntegrate -- Monte Carlo

  • To: mathgroup at
  • Subject: [mg39225] Re: Problem with NIntegrate -- Monte Carlo
  • From: "Carl K. Woll" <carlw at>
  • Date: Tue, 4 Feb 2003 02:23:10 -0500 (EST)
  • Organization: University of Washington
  • References: <b1idic$bjv$>
  • Sender: owner-wri-mathgroup at


The error message occurs because the NIntegrate within ComplicatedF is
complaining about its input. For some reason, the MonteCarlo NIntegrate is
examining the quantity ComplicatedF[x] where x is not numerical. Try
inputting simply ComplicatedF[x] and you will see the same error message.

The way to avoid this situation is to change the function by restricting its
input to only numeric quantities:

ComplicatedF[x_?NumericQ] := Re [NIntegrate [E^(- (I x+y+I)^2), {y,0,1}] ]

Now try your Monte Carlo integration and you will see no errors.

Carl Woll
Physics Dept
U of Washington

"Alan Lewis" <alanlewis at> wrote in message
news:b1idic$bjv$1 at
> I have a rather complicated function that Mathematica can't seem to handle
> with
> NIntegrate, Method->MonteCarlo.
> This is not my function, but it shows the essence of the problem.
> Suppose we have
>    ComplicatedF[x_] :=  Re [NIntegrate [E^(- (I x+y+I)^2), {y,0,1}] ]
> Then, if you try:
> NIntegrate[ComplicatedF[x], {x,0,2}, Method->MonteCarlo]
> Mathematica will complain that the integrand is not numerical.
> But of course it is numerical and removing the Method->MonteCarlo option
> will generate an answer.
> Now my actual function is quite complicated which is why
> I want to try the MonteCarlo method. Any suggestions?

  • Prev by Date: Re: Problem with NIntegrate -- Monte Carlo
  • Next by Date: Re: Another plea for help...
  • Previous by thread: Re: Problem with NIntegrate -- Monte Carlo
  • Next by thread: Processing lists of unrelated numbers with Do or While statement