Re: NIntegrate with change of variables (discovering also a bug in Integrate!?)

*To*: mathgroup at smc.vnet.net*Subject*: [mg77482] Re: NIntegrate with change of variables (discovering also a bug in Integrate!?)*From*: dimitris <dimmechan at yahoo.com>*Date*: Sun, 10 Jun 2007 07:17:28 -0400 (EDT)*References*: <f4drmk$gli$1@smc.vnet.net>

Hi. (Adopted code from R. Gass book (1996), slightly modified and with added comments.) In[4]:= Off[General::spell1] In[5]:= Clear[ContourIntegrate,ContourNIntegrate] In[6]:= ContourNIntegrate[f_(*the function to be integrated*), par : (z_ -> g_) (*the rule z -> g is named par; z is the original variable and g is the contour*), {t_, a_, b_}(* variable and limits of integration*), opts___(*options for NIntegrate; without setting the default are \ used*)] := NIntegrate[Evaluate[(f /. par)*D[g, t]], {t, a, b}, opts] In[7]:= ContourIntegrate[f_(*the function to be integrated*), par : (z_ -> g_) (*the rule z -> g is named par; z is the original variable and g is the contour*), {t_, a_, b_}(*variable and limits of integration*), \ opts___(*options for NIntegrate; without setting the default are used*)] := Integrate[Evaluate[(f /. par)*D[g, t]], {t, a, b}, opts] The first function performs numerical contour integration; the latter symbolic. (*check*) In[15]:= ContourNIntegrate[1/z, z -> Exp[I*t], {t, -Pi, Pi}] Out[15]= 0. + 6.283185307179586*I In[16]:= ContourIntegrate[1/z, z -> Exp[I*t], {t, -Pi, Pi}] Out[16]= 2*I*Pi In[21]:= ContourNIntegrate[z^2/((z - 1/2)*(z - 1/3)*(z - 1/4)), z -> Exp[I*t], {t, -Pi, Pi}, WorkingPrecision -> 40] Out[21]= 0``29.40408430471268 + 6.28318530717958647692528676655900576839433879875`30.202264173070795*I In[26]:= ContourIntegrate[z^2/((z - 1/2)*(z - 1/3)*(z - 1/4)), z -> Exp[I*t], {t, -Pi, Pi}] N[%, 30] Out[26]= 2*I*Pi Out[27]= 6.28318530717958647692528676655900576839433879875`30.*I However you should trust more the ContourNIntegrate that its symbolic counterpart! For example In[29]:= ContourNIntegrate[1/(z - 1/2), z -> Exp[I*t]*(2*Cos[t] + 1), {t, -Pi, Pi}] Out[29]= 0. + 12.566370614352092*I which is correct. The curve encricles the origin two times. In[30]:= ParametricPlot[{Re[Exp[I*t]*(2*Cos[t] + 1)], Im[Exp[I*t]*(2*Cos[t] + 1)]}, {t, 0, 2*Pi}] So from the residue theorem the result of the contour integration should be 2(2Pi) residue of 1/(z-1/2) @ 1/2. In[33]:= 2*(2*Pi*I*Residue[1/(z - 1/2), {z, 1/2}]) N[%] Out[33]= 4*I*Pi Out[34]= 0. + 12.566370614359172*I However In[31]:= ContourIntegrate[1/(z - 1/2), z -> Exp[I*t]*(2*Cos[t] + 1), {t, -Pi, Pi}] Out[31]= (1 + 4*I)*Pi The real part should not have been there! Dimitris / chuck009 : > Hi, > > I'm working on contour integrals using NIntegrate. Can I specify a transformation rule that would replace both the variable of integration as well as the differential? For example, suppose I wish to integrate f(z)dz around the unit circle, that is z=Exp[i t]. Well I could make the transformation: > > NIntegrate[f[z] /. z->Exp[i t],{t,-pi, pi}] but that does not replace dz with its equivalent in terms of t, that is: > > dz=i Exp[i t] dt > > The correct form to integrate would be: > > NIntegrate[f[Exp[i t]] i Exp[i t],{t,-pi, pi}] > > Is there a way to define a transformation rule that would make both those substitutions for unspecified z=g(t)?