Re: Integrate vs. NIntegrate

• To: mathgroup at smc.vnet.net
• Subject: [mg51432] Re: Integrate vs. NIntegrate
• From: Bill Rowe <readnewsciv at earthlink.net>
• Date: Sun, 17 Oct 2004 03:05:24 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 10/16/04 at 4:21 AM, carlos at colorado.edu (Carlos Felippa) wrote:

>Which one is the correct answer?
>
>f=2+Cos[2 x]+ I*Sin[2 x];
>
>Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]]
>//InputForm]; 0.34657359027997264 + 1.5707963267948966*I
>
>Print[            NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi)
>//InputForm]; 0.6931471805599428 + 0.*I
>
>I believe the second one, have doubts about the first.

When I look at the following plots

Plot[Im[Log[f]], {x, -Pi, Pi}];
Plot[Re[Log[f]], {x, -Pi, Pi}];

I see the imaginary portion of f seems to have equal areas above and below the x-axis indicating the imaginary portion of the integral should be near 0. And the plot of the real portion of f is everywhere positive over the range of interest. So, it seems to me clear the first result cannot be correct and I would take the second as correct.

Additionall from what others have reported in this forum, it seems whenever there is a disagreement between using N[Integrate[... and NIntegrate[... it is N[Integrate[... that produces the incorrect answer. In fact, this seems to pop up so often here that I would always use NIntegrate when I wanted a numerical answer instead of converting the results of Integrate to a number.
--
To reply via email subtract one hundred and four

```

• Prev by Date: table format question
• Next by Date: Re: Re: Need help with HISTOGRAM plotting
• Previous by thread: Re: Integrate vs. NIntegrate
• Next by thread: Concatenate matrices