Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Integrate vs. NIntegrate

  • To: mathgroup at
  • Subject: [mg51436] Re: Integrate vs. NIntegrate
  • From: carlos at (Carlos Felippa)
  • Date: Sun, 17 Oct 2004 03:05:37 -0400 (EDT)
  • References: <ckqnbf$nh0$>
  • Sender: owner-wri-mathgroup at

carlos at (Carlos Felippa) wrote in message news:<ckqnbf$nh0$1 at>...
> 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.

The 2nd answer  of Log[2] is verified by a brute force
Gauss-Legendre numerical integrator used in HWs:

NIntGauss3[fx_,x_,lower_,upper_,n_]:= Module[{fint,d,x1,x2,f,
   	d=(upper-lower)/n; fint=0; f=fx;
   	Do[ x1=lower+(i-1)*d; x2=lower+i*d;  
	    fint +=(N[5*f/.x->N[x1*g1+x2*g3]]+

f=2+Cos[2 x]+ I*Sin[2 x];
Print[ NIntGauss3[Log[f],x,-Pi,Pi,200]/(2*Pi) //InputForm];
0.6931471805599455 - 3.969653887102225*^-17*I

Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi)   //InputForm];
0.6931471805599428 + 0.*I

Print[ N[Log[2]] //InputForm];

so NIntegrate[] gives 14 correct digits.

  • Prev by Date: Re: Concatenate matrices
  • Next by Date: Cursor is deactivated after Ctrl+Alt-combination
  • Previous by thread: Re: Integrate vs. NIntegrate
  • Next by thread: Re: Integrate vs. NIntegrate