Re: Integrate vs. NIntegrate
- To: mathgroup at smc.vnet.net
- Subject: [mg51436] Re: Integrate vs. NIntegrate
- From: carlos at colorado.edu (Carlos Felippa)
- Date: Sun, 17 Oct 2004 03:05:37 -0400 (EDT)
- References: <ckqnbf$nh0$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
carlos at colorado.edu (Carlos Felippa) wrote in message news:<ckqnbf$nh0$1 at smc.vnet.net>... > 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, g1=N[(1+Sqrt[3/5])/2],g2=N[1/2],g3=N[(1-Sqrt[3/5])/2]}, 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]]+ N[8*f/.x->N[(x1+x2)/2]]+ N[5*f/.x->N[x1*g3+x2*g1]])*N[d/18], {i,1,n}]; Return[fint]]; 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]; 0.6931471805599453 so NIntegrate[] gives 14 correct digits.