       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

In:=
Off[General::spell1]

In:=
Clear[ContourIntegrate,ContourNIntegrate]

In:=
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:=
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:=
ContourNIntegrate[1/z, z -> Exp[I*t], {t, -Pi, Pi}]
Out=
0. + 6.283185307179586*I

In:=
ContourIntegrate[1/z, z -> Exp[I*t], {t, -Pi, Pi}]
Out=
2*I*Pi

In:=
ContourNIntegrate[z^2/((z - 1/2)*(z - 1/3)*(z - 1/4)), z -> Exp[I*t],
{t, -Pi, Pi}, WorkingPrecision -> 40]
Out=
0``29.40408430471268 +
6.28318530717958647692528676655900576839433879875`30.202264173070795*I

In:=
ContourIntegrate[z^2/((z - 1/2)*(z - 1/3)*(z - 1/4)), z -> Exp[I*t],
{t, -Pi, Pi}]
N[%, 30]

Out=
2*I*Pi
Out=
6.28318530717958647692528676655900576839433879875`30.*I

However you should trust more the ContourNIntegrate that its symbolic
counterpart!

For example

In:=
ContourNIntegrate[1/(z - 1/2), z -> Exp[I*t]*(2*Cos[t] + 1), {t, -Pi,
Pi}]
Out=
0. + 12.566370614352092*I

which is correct.

The curve encricles the origin two times.

In:=
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:=
2*(2*Pi*I*Residue[1/(z - 1/2), {z, 1/2}])
N[%]

Out=
4*I*Pi
Out=
0. + 12.566370614359172*I

However

In:=
ContourIntegrate[1/(z - 1/2), z -> Exp[I*t]*(2*Cos[t] + 1), {t, -Pi,
Pi}]
Out=
(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)?

```

• Prev by Date: Re: Re: Re: Re: v6: still no multiple undo?
• Next by Date: Fast interactive graphics
• Previous by thread: matrix identity pointers
• Next by thread: Fast interactive graphics