NContourIntegrate[f,z∈cont]
gives the numerical integral of f along the contour defined by cont in the complex plane.
NContourIntegrate
NContourIntegrate[f,z∈cont]
gives the numerical integral of f along the contour defined by cont in the complex plane.
Details and Options
- Contour integration is also known as path integration or complex line integration.
- Contour integrals arose in the study of holomorphic and meromorphic functions in complex analysis, but they are now used in a wide range of applications, including the computation of inverse Laplace transforms and Z transforms, definite integrals and sums, and solutions of partial differential equations.
- The contour integral of a function
along a contour cont
is given by: - The value of the contour integral is independent of the parametrization, but it does depend on the orientation of the contour cont.
- The function f is typically a meromorphic function of z, but it can be any piecewise continuous function that is defined in a neighborhood of cont in the complex plane.
- The contour integral of a meromorphic function
along a closed contour cont can be computed using Cauchy's residue theorem. - Commonly used closed contours cont include: »
-

{"Hairpin",hl} encircle a half-line hl 
{"UpperSemicircle",ipts,epts} encircle the upper half-plane, including the points ipts and excluding the points epts, all on the real axis 
{"LowerSemicircle",ipts,epts} encircle the lower half-plane, including the points ipts and excluding the points epts, all on the real axis 
{"Dumbbell",pt1,pt2} encircle the capsule given by points pt1 and pt2 - The complex points are given as {x,y} pairs; complex half-lines are given as HalfLine primitives.
- A contour cont in
can also be specified as a curve region (RegionQ) in
. - For a parametric contour ParametricRegion[{x[t],y[t]},{{t,a,b}}], the orientation is in the direction of increasing t.
- Special contours in
and their assumed orientations: -

Line[{p1,p2,…}] from p1 to p2 etc. 
HalfLine[{p1,p1}] from p1 toward p2 
InfiniteLine[{p1,p2}] from p1 toward p2 
Circle[p,…] counterclockwise - Area regions such as Polygon can be used, and the contours are then taken to be the boundary contours RegionBoundary[Polygon[…]].
- Special area regions in
and their assumed boundary contour orientations: -

Triangle[{p1,p2,p3}] counterclockwise 
Rectangle[p1,p2] counterclockwise 
RegularPolygon[n,…] counterclockwise 
Polygon[{p1,p2,…}{{q1,q2,…},…}] counterclockwise of the outer contour, clockwise for inner contours 
Disk[p,…] counterclockwise 
Ellipsoid[p,…] counterclockwise 
StadiumShape[{p1,p2},r] counterclockwise 
Annulus[p,{rm,rm},…] counterclockwise for outer contour and clockwise for inner contour - The regions in cont may be wrapped with Inactive to prevent auto-evaluation.
- The following options can be given:
-
AccuracyGoal Automatic digits of absolute accuracy sought MaxPoints Automatic maximum total number of sample points MaxRecursion Automatic maximum number of recursive subdivisions Method Automatic method to use MinRecursion 0 minimum number of recursive subdivisions PrecisionGoal Automatic digits of precision sought WorkingPrecision Automatic the precision used in internal computations
Examples
open all close allBasic Examples (3)
Integrate 1/z along the unit circle:
NContourIntegrate[1 / z, z∈Circle[]]Integrate a rational function along a circle with a center at the origin and radius 2:
Show[ComplexPlot[(z^3 (1 - 5 z)/(1 + z) (1 + 2 z^4)), {z, -4 - 4I, 4 + 4I}], ...]NContourIntegrate[(z ^ 3(1 - 5z)/(1 + z) (1 + 2 z^4)), z∈Circle[{0, 0}, 3]]Integrate a meromorphic function along an elliptical contour:
Show[ComplexPlot[(Cos[z]/z(z^2 + 3)(z - 2)), {z, -4 - 4I, 4 + 4I}], ...]NContourIntegrate[(Cos[z]/z(z^2 + 3)(z - 2)), z∈Circle[{0, 0}, {1, 3}]]Compare the result with ContourIntegrate:
ContourIntegrate[(Cos[z]/z(z^2 + 3)(z - 2)), z∈Circle[{0, 0}, {1, 3}]]N[%]Scope (46)
Basic Uses (9)
Contour integral over a circular path:
f = (1/(z - 1)^2 (z - I));ComplexPlot[f, {z, -3 - 3I, 3 + 3I}, ...]NContourIntegrate[f, z∈Circle[{1, 0}, 1]]Compare to ContourIntegrate:
ContourIntegrate[f, z∈Circle[{1, 0}, 1]]Contour integral over a polygonal chain in the complex plane:
f = Exp[2z] / (z - 1);reg = Line[{{0, 0}, {1, 1}, {2, 0}}];ComplexPlot[f, {z, -1 - I, 3 + 3I}, ...]NContourIntegrate[f, z∈reg]Contour integrate over a half-disk:
f = Sin[Pi * z] ^ 2 / (z - 1 - I);reg = Disk[{0, 0}, 3, {0, Pi}];NContourIntegrate[f, z∈reg]Numerical contour integral of a trigonometric expression:
f = Sin[z ^ 2 + 1 / z] ^ 3;reg = Circle[];NContourIntegrate[f, z∈reg]Contour integral over a parametric contour in the complex plane:
reg = ParametricRegion[{Cos[t], Sin[t]}, {{t, 0, 2Pi}}];NContourIntegrate[1 / z, z∈reg]Contour integral of a meromorphic function over a closed semicircle:
f = (Cosh[z^2 - 1]/z^3 + I / 2);reg = Disk[{0, 0}, 1, {0, Pi}];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral of a function with an essential singularity:
f = (Cos[1 / z]/z);reg = Circle[];ComplexPlot[f, {z, -2 - 2I, 3 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral of a non-analytic function:
f = Exp[1 / Conjugate[z]];reg = Line[{{-1, -1}, {0, -1}, {1, -3 / 2}}];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, Epilog -> {RGBColor[0.33333333333333337, 0.33333333333333337, 0.33333333333333337], Arrow@reg}, ImageSize -> Small]NContourIntegrate[f, z∈reg]Contour integral of a function containing a branch cut:
f = Log[z ^ 2 - 1 / 2];reg = Circle[];ComplexPlot[f, {z, -1.5 - 1.5I, 1.5 + 1.5I}, ...]NContourIntegrate[f, z∈reg, AccuracyGoal -> 5]Special Topic: Rational Functions (8)
Integrate a rational function along a circle:
NContourIntegrate[(3z ^ 3 + 2) / ((z - 1)(z ^ 2 + 9)), z∈Circle[{0, 0}, 4]]Integrate a rational function along a pentagonal contour:
ComplexPlot[((z ^ 5 + 1) ^ 8/(z - I / 2)(z - 1 / 3) ^ 2), {z, -1 - I, 1 + I}, ...]NContourIntegrate[(z ^ 5 + 1/(2z - I)(3z - 1) ^ 3), z∈RegularPolygon[5]]Contour integral of a rational function along a triangular path:
f = ((z - I) ^ 3/(z - 1)(z - 2)(z - 3));reg = Triangle[{{2, 1}, {-2, 0}, {3, -1}}];ComplexPlot[f, {z, -4 - 2I, 4 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral of a rational function along a rectangular path:
f = (z^4 + 1/(z^2 - 1)^2 + 3);reg = Rectangle[{-2, 0}, {2, 1}];ComplexPlot[f, {z, -5 / 2 - 2I, 5 / 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral along the unit circle:
f = (z ^ 6 - 2I * z ^ 5 + 3 / 2z ^ 3 - 1) / (z(z ^ 2 - z - I) ^ 2);reg = Circle[];ComplexPlot[f, {z, -3 / 2 - 3I / 2, 3 / 2 + 3I / 2}, ...]NContourIntegrate[f, z∈reg]Contour integral over an open polygonal chain:
f = ((z + 1) ^ 2(z - 2 - 2I) ^ 3/z^2(z - 1 / 2) ^ 2(z - 3 + I));reg = Line[{{1, 0}, {2, 1}, {3, 0}, {4, 1}}];ComplexPlot[f, {z, -1 - 2I, 9 / 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral over an open arc:
f = (2z(z + 2)/z - 2);reg = Circle[{0, 0}, {1 / 2, 1}, {0, (7Pi/4)}];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral of a rational function along a circular path:
f = (z - 2) ^ 2 / (z - 1 / 2);reg = Circle[];NContourIntegrate[f, z∈reg]Special Topic: Meromorphic Functions (5)
Contour integral of a meromorphic function along a polygonal path:
f = (z^2 + I/(z - I / 2)Cos[3z]);reg = RegularPolygon[5];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Evaluate the contour integral symbolically:
ContourIntegrate[f, z∈reg]N[%]Contour integral along an elliptical path:
f = (Sin[z]/z(z^2 + 3)(z - 2));reg = Circle[{0, 0}, {1, 3}];ComplexPlot[f, {z, -4 - 4I, 4 + 4I}, ...]NContourIntegrate[f, z∈reg]Contour integral over a closed semicircle:
f = (Cosh[z^2 - 1 / 4]/z^2 + 1 / 4);reg = Disk[{0, 0}, 1, {0, Pi}];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral over a sector of annulus:
f = Tan[z - I];reg = Annulus[{0, 0}, {1, 3}, {0, Pi}];ComplexPlot[f, {z, -7 / 2 - 7I / 2, 7 / 2 + 7I / 2}, ...]NContourIntegrate[f, z∈reg]Contour integral over a circle of radius 6:
NContourIntegrate[1 / Sin[z], z∈Circle[{0, 0}, 6]]Special Topic: Functions with Essential Singularities (4)
f = Exp[1 / z];reg = Circle[];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Sin function with an essential singularity inside the contour:
f = (Sin[1 / z]/z^4 + I);reg = Rectangle[{-1 / 2, -1 / 2}, {1, 1}];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral of a function with an essential singularity:
f = (Tanh[1 / z]/(z - 1)(z + I / 2));reg = Disk[{-1 / 2, -1}, {1, 3 / 2}, {0, Pi / 2}];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Essential singularity arising from a periodic function:
f = (Cos[2 - 1 / z]/z);reg = Annulus[{-1 / 2, -1}, {1 / 2, 3 / 2}, {0, Pi / 2}];ComplexPlot[f, {z, -2 - 2I, 3 + 2I}, ...]NContourIntegrate[f, z∈reg]Special Topic: Non-analytic Functions (4)
Contour integral over a circular path:
f = Conjugate[z];reg = Circle[];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Contour integral of the Arg function:
f = Arg[z];reg = Circle[{0, 0}, 2];ComplexPlot[f, {z, -3 - 3I, 3 + 3I}, ...]NContourIntegrate[Arg[z], z∈reg]Contour integral over an elliptic sector:
f = (1/z - Conjugate[z] + 1);reg = Disk[{0, 0}, {1, 2}, {-Pi / 8, 11Pi / 8}];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]//SimplifyContour integral over a rectangular path:
f = (Exp[Conjugate[z]]/z + Conjugate[z]);reg = Rectangle[{-5 / 2, -5 / 2}, {-1, -1}];ComplexPlot[f, {z, -6 / 2 - 6 / 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]Special Topic: Functions with Branch Cuts (2)
Contour integral of a piecewise continuous function:
f = Sqrt[z ^ 3 - I / 2];reg = Circle[];ComplexPlot[f, {z, -1.5 - 1.5I, 1.5 + 1.5I}, ...]NContourIntegrate[f, z∈reg, WorkingPrecision -> 20, MaxRecursion -> 20, AccuracyGoal -> 6]//QuietContour integral of a function with branch cuts on the integration path:
f = (z^2/Sqrt[z^2 + 1 / 2]);reg = Circle[];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]//QuietSpecial Topic: Named Contours (7)
Contour integral along the real axis in a positive direction, around poles on the real axis, closing in the upper half of the complex plane:
NContourIntegrate[I E ^ (I p) / (p ^ 2 - 4), p∈{"UpperSemicircle", 2, -2}]ContourIntegrate[I E ^ (I p) / (p ^ 2 - 4), p∈{"UpperSemicircle", 2, -2}]%//NComplexPlot[I E ^ (I p) / (p ^ 2 - 4), {p, -4 - 4I, 4 + 4I}, ...]NContourIntegrate[I E ^ (I p) / (p ^ 2 - 1) / (p - I / 2), p∈{"UpperSemicircle", Point[{1, 0}], Point[{-1, 0}]}]ContourIntegrate[I E ^ (I p) / (p ^ 2 - 1) / (p - I / 2), p∈{"UpperSemicircle", Point[{1, 0}], Point[{-1, 0}]}]%//NContour integral along the real axis in a positive direction, around poles on the real axis, closing in the lower half of the complex plane:
NContourIntegrate[I E ^ (-I p) / (p ^ 2 - 4), p∈{"LowerSemicircle", -2, 2}, MaxRecursion -> 20]ContourIntegrate[I E ^ (-I p) / (p ^ 2 - 4), p∈{"LowerSemicircle", -2, 2}]%//NComplexPlot[I E ^ (-I p) / (p ^ 2 - 4), {p, -4 - 4I, 4 + 4I}, ...]By default, this contour is traversed clockwise.
NContourIntegrate[I E ^ (-2I p) / (p ^ 2 - 1) / (p + 3I), p∈{"LowerSemicircle", Point[{-1, 0}], Point[{1, 0}]}, MaxRecursion -> 20]ContourIntegrate[I E ^ (-2I p) / (p ^ 2 - 1) / (p + 3I), p∈{"LowerSemicircle", Point[{-1, 0}], Point[{1, 0}]}]%//NContour integral around a hairpin or Hankel contour:
NContourIntegrate[(-z) ^ (1 / 2)E ^ (-z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]ContourIntegrate[(-z) ^ (1 / 2)E ^ (-z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]%//NComplexPlot[(-z) ^ (1 / 2)E ^ (-z), {z, -2 - 2I, 3 + 3I}, ...]Integral around a hairpin or Hankel contour:
NContourIntegrate[(-z) ^ (1 / 3 - 1)E ^ (-z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]Compare to the symbolic evaluation:
ContourIntegrate[(-z) ^ (1 / 3 - 1)E ^ (-z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]%//NComplexPlot[(-z) ^ (1 / 3 - 1)E ^ (-z), {z, -2 - 2I, 3 + 3I}, ...]Contour integral that evaluates to a Zeta function:
ContourIntegrate[(-z) ^ (14 / 9 - 1)E ^ (-3 z) / (1 - E ^ -z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]%//NNContourIntegrate[(-z) ^ (14 / 9 - 1)E ^ (-3 z) / (1 - E ^ -z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]ComplexPlot[(-z) ^ (14 / 9 - 1)E ^ (-3 z) / (1 - E ^ -z), {z, -3 - 3I, 3 + 3I}, ...]NContourIntegrate[E ^ (-z - 1 / 2z ^ 2)(-z) ^ (3 / 2 - 1), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]ComplexPlot[E ^ (-z - 1 / 2z ^ 2)(-z) ^ (3 / 2 - 1), {z, -3 - 3I, 3 + 3I}, ...]Dumbbell contour around the branch cut, joining 0 and 1:
NContourIntegrate[Log[z / (z - 1)], z∈{"Dumbbell", 0, 1}]ComplexPlot[Log[z / (z - 1)], {z, -1 - I, 2 + 2I}, ...]Special Topic: Region Contours (7)
Contour integral over an infinite line:
NContourIntegrate[1 / (s + 1)(1 / 2) ^ -s, s∈InfiniteLine[{1, 0}, {0, 1}]]ComplexPlot[1 / (s + 1) * (1 / 2) ^ -s, {s, -20 - 20I, 20 + 20I}, ...]Contour integral over a circular contour:
NContourIntegrate[1 / (z - 1 / 2), z∈Circle[]]Contour integral over a line segment:
NContourIntegrate[(z + 1)(z - I)(z + 2I - 1), z∈Line[{{0, 0}, {1, 1}}]]ComplexPlot[(z + 1)(z - I)(z + 2I - 1), {z, -3 - 3I, 3 + 3I}, ...]Contour integral over a triangular path:
reg = Triangle[{{0, 1}, {-1, 0}, {1, 0}}];NContourIntegrate[Sinh[z ^ 2] / (z - I / 2), z∈reg]ComplexPlot[Sinh[z ^ 2] / (z - I / 2), {z, -2 - I, 2 + 2I}, ...]Contour integral over a rectangular path:
reg = Rectangle[{-1, -1}, {1, 1}];NContourIntegrate[E ^ (I z) / (z ^ 2 + 1 / 4), z∈reg]ComplexPlot[E ^ (I z) / (z ^ 2 + 1 / 4), {z, -2 - 2I, 2 + 2I}, ...]Contour integral over a sector:
reg = Disk[{0, 0}, {1, 2}, {0, Pi / 3}];NContourIntegrate[Cosh[z ^ 3] / (z - 1 / 2 - I), z∈reg]ComplexPlot[Cosh[z ^ 3] / (z - 1 / 2 - I), {z, -1 - I, 2 + 2I}, ...]Contour integral over an annulus:
reg = Annulus[{0, 0}, {1, 2}, {0, Pi}];NContourIntegrate[ArcTan[z + 2] / (z ^ 2 + 3 / 2), z∈reg]ComplexPlot[ArcTan[z + 2] / (z ^ 2 + 3 / 2), {z, -3 - I, 3 + 3I}, ...]Options (7)
AccuracyGoal (1)
The option AccuracyGoal sets the number of digits of accuracy:
exact = ContourIntegrate[1 / z, z∈Circle[{2, 0}]]NContourIntegrate[1 / z, z∈Circle[{2, 0}], AccuracyGoal -> 15] - exactThe result with default settings only sets a PrecisionGoal:
NContourIntegrate[1 / z, z∈Circle[{2, 0}]] - exactMaxPoints (1)
The option MaxPoints stops the integration after a specified number of points has been evaluated:
NContourIntegrate[1 / Abs[z] ^ 8, z∈Line[{{0, 1}, {1, 0}}], MaxPoints -> 5, WorkingPrecision -> 9]NContourIntegrate[1 / Abs[z] ^ 8, z∈Line[{{0, 1}, {1, 0}}], WorkingPrecision -> 9]MaxRecursion (1)
The option MaxRecursion specifies the maximum number of recursive steps:
NContourIntegrate[(-z) ^ (1 / 2)E ^ (-z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}, MaxRecursion -> 5]Increasing the number of recursions:
NContourIntegrate[(-z) ^ (1 / 2)E ^ (-z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}, MaxRecursion -> 25]ContourIntegrate[(-z) ^ (1 / 2)E ^ (-z), z∈{"Hairpin", HalfLine[{0, 0}, {1, 0}]}]%//NMethod (1)
The option Method can take the same values as in NIntegrate. For example:
NContourIntegrate[(z - 3) / (z - I / 2), z∈Circle[], Method -> "TrapezoidalRule", WorkingPrecision -> 9]NContourIntegrate[(z - 3) / (z - I / 2), z∈Circle[], Method -> "NewtonCotesRule", WorkingPrecision -> 9]NContourIntegrate[(z - 3) / (z - I / 2), z∈Circle[], Method -> "ClenshawCurtisRule", WorkingPrecision -> 9]NContourIntegrate[(z - 3) / (z - I / 2), z∈Circle[], WorkingPrecision -> 9]Compare to the truncated exact result:
ContourIntegrate[(z - 3) / (z - I / 2), z∈Circle[]]%//N[#, 9]&MinRecursion (1)
The option MinRecursion forces a minimum number of subdivisions:
NContourIntegrate[Exp[-300Abs[z] ^ 2], z∈Line[{{-70, -70}, {70, 70}}]]NContourIntegrate[Exp[-300Abs[z] ^ 2], z∈Line[{{-70, -70}, {70, 70}}], MinRecursion -> 5]ContourIntegrate[Exp[-300Abs[z] ^ 2], z∈Line[{{-70, -70}, {70, 70}}]]%//NPrecisionGoal (1)
The option PrecisionGoal sets the relative tolerance in the integration:
exact = ContourIntegrate[1 / (1 / 2 + Sin[z]), z∈Circle[]]NContourIntegrate[1 / (1 / 2 + Sin[z]), z∈Circle[], PrecisionGoal -> 15] - exactNContourIntegrate[1 / (1 / 2 + Sin[z]), z∈Circle[]] - exactWorkingPrecision (1)
Using WorkingPrecision, the working precision can be set:
f = Exp[Tan[2 + 1 / z]];NContourIntegrate[f, z∈Circle[]]NContourIntegrate[f, z∈Circle[], WorkingPrecision -> 25]Applications (22)
Rational Functions (2)
Contour integral on a half-disk of large radius:
NContourIntegrate[(1/z^2 + 1), z∈Disk[{0, 0}, 10 ^ 4, {0, Pi}]]It agrees with the limit for large
computed symbolically:
Limit[ContourIntegrate[(1/z^2 + 1), z∈Disk[{0, 0}, R, {0, Pi}]], R -> ∞]The same result obtained with NIntegrate:
NIntegrate[(1/x^2 + 1), {x, -∞, ∞}]NIntegrate[(x^2/(x^2 + 1)(x^2 + 4)), {x, -∞, ∞}]This can be obtained as the limit of a contour integral:
NContourIntegrate[(z^2/(z^2 + 1)(z^2 + 4)), z∈Disk[{0, 0}, 10 ^ 4, {0, Pi}]]Trig-Rational Products (2)
NIntegrate[(Cos[2x]/(x^2 + 3^2)^2), {x, -∞, ∞}]NIntegrate[(Sin[2x]/(x^2 + 3^2)^2), {x, -∞, ∞}]These two results can be recovered using a complex integral along a half-disk of large radius:
res = NContourIntegrate[(Exp[2 I z]/(z^2 + 3^2)^2), z∈Disk[{0, 0}, 10 ^ 4, {0, Pi}], Rule[...]]{Re[%], Im[%]}//ChopNIntegrate[(x Sin[2x]/x^2 + 3), {x, -∞, ∞}]NIntegrate[(x Cos[2x]/x^2 + 3), {x, -∞, ∞}]NContourIntegrate[(z Exp[I 2 z]/z^2 + 3), z∈Disk[{0, 0}, 10 ^ 4, {0, Pi}], MaxRecursion -> 20]{Im[%], Re[%]}//ChopTrigonometric Functions (3)
Integral of a rational function of the sine:
f = (1/1 + 1 / 2 * Sin[θ]);NIntegrate[f, {θ, 0, 2Pi}]This can be recovered as a contour integral:
g = f /. {Sin[θ] -> (z - z^-1/2I)}//FullSimplifyNContourIntegrate[(g/I z), z∈Circle[]]Integral of a rational function of the cosine:
f = (2Cos[2θ]Sin[3θ] ^ 6/1 - 4Cos[θ] + 4);NIntegrate[f, {θ, 0, 2Pi}]This can be obtained as a contour integral:
g = (f//TrigExpand) /. {Sin[θ] -> (z - z^-1/2I), Cos[θ] -> (z + z^-1/2)}//FullSimplifyNContourIntegrate[(g/I z), z∈Circle[]]Integral of a rational function of the sine:
f = (1/5 + 4Sin[θ] ^ 7);NIntegrate[f, {θ, 0, 2Pi}]g = f /. {Sin[θ] -> (z - z^-1/2I)}//FullSimplifyNContourIntegrate[(g/I z), z∈Circle[]]Fourier Transform (2)
Fourier transform of a function:
ft = FourierTransform[(1/x^2 + 1), x, k]ft /. k -> 2//NComputation using a numerical contour integral:
(1/Sqrt[2Pi])NContourIntegrate[(Exp[2I z]/z^2 + 1), z∈Disk[{0, 0}, 10 ^ 4, {0, Pi}], Rule[...]]ft /. k -> -2//N(-1/Sqrt[2Pi])NContourIntegrate[(Exp[-2I z]/z^2 + 1), z∈Disk[{0, 0}, 10 ^ 4, {-Pi, 0}], MaxRecursion -> 20]Fourier transform of a function:
ft = FourierTransform[(1/-2 + 2x - x^2), x, k]Computation using a contour integral: for positive
:
ft /. k -> 2//N(1/Sqrt[2Pi])NContourIntegrate[(Exp[2I z]/-2 + 2z - z^2), z∈Disk[{0, 0}, 10 ^ 4, {0, Pi}], Rule[...]]ft /. k -> -2//N(-1/Sqrt[2Pi])NContourIntegrate[(Exp[-2I z]/-2 + 2z - z^2), z∈Disk[{0, 0}, 10 ^ 3, {-Pi, 0}]]Inverse Laplace Transform (4)
Inverse Laplace transform of a function:
ilt = InverseLaplaceTransform[1 / (s + 1), s, t, GenerateConditions -> True]ilt /. t -> 3//NComputation using a contour integral:
1 / (2Pi I)NContourIntegrate[1 / (s + 1) * E ^ (3s), s∈InfiniteLine[{1, 0}, {0, 1}]]Inverse Laplace transform of a logarithm of a rational function:
f = Log[(s + 1) / (s + 2)];ilt = InverseLaplaceTransform[f, s, t, GenerateConditions -> True]ilt /. t -> 2//N1 / (2Pi I)NContourIntegrate[f * E ^ (2s), s∈InfiniteLine[{1, 0}, {0, 1}]]Inverse Laplace transform of a function containing a square root:
ilt = InverseLaplaceTransform[1 / Sqrt[s + 1], s, t, GenerateConditions -> True]ilt /. t -> 1 / 2//NThe same computation using a contour integral:
1 / (2Pi I)NContourIntegrate[1 / Sqrt[s + 1] * E ^ (s / 2), s∈InfiniteLine[{1, 0}, {0, 1}], MaxRecursion -> 50]Inverse Laplace transform of a function containing Log:
ilt = InverseLaplaceTransform[Log[s] / (s - 1), s, t, GenerateConditions -> True]ilt /. t -> 3 / 2//NUse the definition of the inverse Laplace transform:
1 / (2Pi I)NContourIntegrate[Log[s] / (s - 1) * E ^ (s * 3 / 2), s∈InfiniteLine[{1, 0}, {0, 1}], MaxRecursion -> 20]Inverse Mellin Transform (4)
Inverse Mellin transform of a function:
imt = InverseMellinTransform[(1/s^2 - 1), s, x, GenerateConditions -> True]imt /. x -> 1 / 2//NCompute it from a contour integral:
1 / (2Pi I)NContourIntegrate[(1 / 2) ^ (-s) * (1/s^2 - 1), s∈InfiniteLine[{{2, 0}, {2, 1}}]]Inverse Mellin transform of a function:
imt = InverseMellinTransform[1 / (s - 1), s, x, GenerateConditions -> True]Assuming[Re[s] > 1, Simplify[imt]] /. x -> 1 / 5//NCompute it from its definition as a contour integral:
1 / (2Pi I)NContourIntegrate[1 / (s - 1) * (1 / 5) ^ -s, s∈InfiniteLine[{2, 0}, {0, 1}]]Mellin transform of a function:
f = (1/(1 + x)^3);MellinTransform[f, x, s, GenerateConditions -> True]Recover the function at
using an inverse Mellin transform:
1 / (2Pi I)NContourIntegrate[Gamma[s]Gamma[3 - s] / 2 * (1 / 3) ^ -s, s∈InfiniteLine[{2, 0}, {0, 1}]]f /. x -> 1 / 3//NMellin transform of a rational function:
f = (x ^ 2/(1 + x)^3);MellinTransform[(x ^ 2/(1 + x)^3), x, s, GenerateConditions -> True]Recover the function at
using an inverse Mellin transform:
1 / (2Pi I)NContourIntegrate[(1/2) π s (1 + s) Csc[π s] * (2 / 3) ^ -s, s∈InfiniteLine[{0, 0}, {0, 1}]]f /. x -> 2 / 3//NInverse Z Transform (2)
Inverse Z transform of a function:
InverseZTransform[z / (z - 2), z, n]% /. n -> 3Obtain the result from its definition as a contour integral:
(1/2Pi I)NContourIntegrate[(z^3/(z - 2)), z∈Circle[{0, 0}, 10 ^ 3]]Inverse Z transform of a function:
f = InverseZTransform[z / (z ^ 2 - 3 z + 1), z, n]f /. n -> 7//NFrom its definition as a contour integral of large radius:
(1/2Pi I)NContourIntegrate[z^n / (z ^ 2 - 3 z + 1) /. n -> 7, z∈Circle[{0, 0}, 10 ^ 3], ...]Classical Theorems (3)
Residue theorem applied to the contour integral of a meromorphic function over a closed path:
f = 3z ^ 2 / (z ^ 3 - 1 / 2);reg = Circle[];ComplexPlot[f, {z, -2 - 2I, 2 + 2I}, ...]NContourIntegrate[f, z∈reg]The integral is equal to
times the sum of the residues of the poles inside the contour:
(2Pi I) * ResidueSum[{f, Abs[z] < 1}, z]//NThe integration contour can be deformed without changing the value of the integral, provided that no singularities of the function are crossed:
f = 1 / (z - 2) + 1 / (z - 3);reg1 = Line[{{-1, 0}, {0, 1}, {1, 0}}];NContourIntegrate[f, z∈reg1]reg2 = Line[{{-1, 0}, {0, -1}, {1, 0}}];NContourIntegrate[f, z∈reg2]If no singularities lie inside the contour, the integral is zero:
NContourIntegrate[1 / (z - 2), z∈Circle[], AccuracyGoal -> 5]ComplexPlot[1 / (z - 2), {z, -3 - 3I, 3 + 3I}, ...]Properties & Relations (6)
Apply N[ContourIntegrate[…]] to obtain a numerical solution if the symbolic calculation fails:
f = Exp[Tan[2 + 1 / z]];ContourIntegrate[f, z∈Circle[]]N[%]This can also be computed using NIntegrate:
NIntegrate[I * E ^ (I t) * (f /. z -> E ^ (I t)), {t, 0, 2Pi}]It can also be computed with NContourIntegrate:
NContourIntegrate[f, z∈Circle[]]Numerical contour integrals can also be obtained using NIntegrate:
NContourIntegrate[1 / (z - 1 / 2), z∈Circle[]]NIntegrate[I * E ^ (I t) / (E ^ (I t) - 1 / 2), {t, 0, 2Pi}]NIntegrate can integrate along a straight contour in the complex plane:
NIntegrate[z ^ 2, {z, 0, 1 + I}]NContourIntegrate[z ^ 2, z∈Line[{{0, 0}, {1, 1}}]]Contour integrals over a closed path can also be obtained using ResidueSum:
f = z ^ 2 / (2z ^ 3 - 1);NContourIntegrate[f, z∈Circle[{0, 0}, 2]]2πI * ResidueSum[{f, Abs[z] < 2}, z]//NPoles of a meromorphic function can be found using FunctionPoles:
f = Cos[z] / (z + 1 / 2);FunctionPoles[f, z]NContourIntegrate[f, z∈Circle[{0, 0}, 1]]The integral can also be computed using Residue:
2π I * Residue[f, {z, -1 / 2}]//NContour integrals over a closed path can also be obtained using Residue:
f = z ^ 2 / ((z - 1)(z - 2));NContourIntegrate[f, z∈Circle[{0, 0}, 3]]2π I * (Residue[f, {z, 1}] + Residue[f, {z, 2}])//NInteractive Examples (2)
Contour integral over a sector of varying radius:
f = (1/z^2 + 1);Manipulate[
ComplexPlot[f, {z, -6 - 6I, 6 + 6I}, ...]
, {R, 0.1, 7}, SaveDefinitions -> True]Manipulate[NContourIntegrate[f, z∈Disk[{0, 0}, R, {0, Pi}]], {R, 0.1, 7}, SaveDefinitions -> True]Compare with ContourIntegrate:
ContourIntegrate[f, z∈Disk[{0, 0}, R, {0, Pi}]]Another contour integral over a sector of varying radius:
f = (1/z^6 + 1);Manipulate[
ComplexPlot[f, {z, -6 - 6I, 6 + 6I}, ...], {R, 0.1, 7}, SaveDefinitions -> True]Manipulate[NContourIntegrate[f, z∈Disk[{0, 0}, R, {0, Pi}]], {R, 0.1, 7}, SaveDefinitions -> True]Compare with ContourIntegrate:
ContourIntegrate[f, z∈Disk[{0, 0}, R, {0, Pi}]]Related Guides
History
Text
Wolfram Research (2024), NContourIntegrate, Wolfram Language function, https://reference.wolfram.com/language/ref/NContourIntegrate.html.
CMS
Wolfram Language. 2024. "NContourIntegrate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NContourIntegrate.html.
APA
Wolfram Language. (2024). NContourIntegrate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NContourIntegrate.html
BibTeX
@misc{reference.wolfram_2026_ncontourintegrate, author="Wolfram Research", title="{NContourIntegrate}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NContourIntegrate.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_ncontourintegrate, organization={Wolfram Research}, title={NContourIntegrate}, year={2024}, url={https://reference.wolfram.com/language/ref/NContourIntegrate.html}, note=[Accessed: 13-June-2026]}