Re: Integrate vs NIntegrate
- To: mathgroup at smc.vnet.net
- Subject: [mg89149] Re: Integrate vs NIntegrate
- From: "Armen Kocharyan" <armen.kocharyan at gmail.com>
- Date: Tue, 27 May 2008 07:14:27 -0400 (EDT)
- References: <2b8d8f40805252204g6aca77a0tf53fc8c31779c64a@mail.gmail.com>
My guess is that it's a bug. Mathematica adds two different constants to two branches (x<2, x>2). The following "fixes" the problem Clear[x]; q = -1/2; h[x_] = (1 + x^3)^q; (*wrong f-fw*) fw[x_] = Integrate[h[x], x]; fw1[x_] = (fw[x] - fw[0])*UnitStep[2 - x]; fw2[x_] = (fw[x] + fw[2] - Im[fw[3]] \[ImaginaryI])*UnitStep[x - 2]; (*right f-fr*) fr[x_] = fw1[x] + fw2[x]; (*correct f*) f[x_] = Integrate[h[z], {z, 0, x}, Assumptions -> x >= 0]; (*correct and wrong f*) Plot[{f[x], Re[fw[x]], Im[fw[x]]}, {x, 0, 10}] (*fixed f*) Plot[fr[x], {x, 0, 10}] One may have to fix fr[2] as well. Regards, Armen 2008/5/26 Armen Kocharyan <armen.kocharyan at gmail.com>: > Dear group, > > > Why do I get different results (Res1, Res2) in Mathematica 6.0.1.0? > > > *q=-1/2; a=0; b=3;* > > *h[x_]=(1+x^3)^q;* > > *f[x_]=Integrate[h[x],x];* > > *Res1=N[f[b]-f[a]]* > > *Res2=NIntegrate[h[x],{x,a,b}]* > > ** > > *Res1 = -2.55387-2.42865 i* > > *Res2 = 1.65267* > > > > I'm assuming that Res2 is the correct answer. > > > > Regards, > > Armen >