Stokes' theorem

Green's Theorem expresses the line integral of a vector field around a
closed plane curve in terms of the double integral over the region bounded
by the curve. This notebook illustrates how the converse problem
(expressing a double integral over a region in terms of a line integral
around the boundary of the region) can be solved in Mathematica.

The function

Stokes[function, {var1, var1min,var1max},{var2,var2min,var2max}] gives the line integral around the rectangular boundary define by the vertical and horizontal lines defined by var1min, var1max, var2min, var2max.

Stokes[func1_,{var1_,xmin_,xmax_},{var2_,ymin_,ymax_}]:=Module[{func,rr,tt},
func[rr_,tt_]:=If[Head[func1]===Symbol&&(func1=!=var1||func1=!=var2),func1[rr,tt],func1/.{var1->rr,var2->tt}];
-Integrate[Integrate[func[rr,tt],rr]/.{rr->xmin},{tt,ymin,ymax}]+Integrate[Integrate[func[rr,tt],rr]/.{rr->xmax},{tt,ymin,ymax}]]

Some examples

Here is an example using the basic function.

ff[x_,y_,z_] :=-z/((x-1)^2+(y-1)^2+z^2)^(3/2)

Stokes[-z/((x-1)^2+(y-1)^2+z^2)^(3/2),{x,2,5},{y,3,7}]//Simplify

Here is an example using a change of variables to integrate around the diamond shaped path defined by {{1,0},{0,1},{-1, 0}, {0, -1}}. The change of variable formulas are given by:

u = x + y
v = x - y

This gives rise to a Jacobian of 1/2.

gg[x_,y_,z_] := (x^2) + (y^2) - (z^2)+ 2

Stokes[gg[(u+v)/2,(u-v)/2,z]/2,{u,-1,1},{v,-1,1}]

We can check this result using the standard double integral.

Integrate[gg[x,y,z],{x,-1,0},{y,-x-1,x+1}]+Integrate[gg[x,y,z],{x,0,1},{y,x-1,-x+1}]

We can also enter our function directly.

gg[(u+v)/2,(u-v)/2,z]/2

Stokes[(1/2) (2+(1/4) (((u-v))^2)+(1/4) (((u+v))^2)-(z^2)),{u,-1,1},{v,-1,1}]