Application Center - Maplesoft

# Stokes' Theorem

You can switch back to the summary page by clicking here.

Stokes' Theorem
Attila Andai
Mathematical Institute, Budapest University of Technology and Economics

Hungary

andaia@math.bme.hu
This Maple worksheet demonstrates Stokes' Theorem.

Mathematical implementation of Stokes' Theorem

In this section we explain the mathematical implementation of the Theorem, using an example.

We consider a five dimensional Euclidean vector space V. The manifold G is the closed sphere with radius and center origin.

 > restart;

 > with(tensor): with(linalg): with(combinat):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the assigned name fibonacci now has a global binding

Warning, the protected name Chi has been redefined and unprotected

Input

N: Dimension of the vector space V.
M
: Dimension of the manifold G.

 > N:=5; M:=5;

Input

parcord: List, which contains the name of the coordinates of the manifold G, it contains M symbols.

p[i]: Parametrization of the manifold G, the index i runs from 1 to N, and p[i] is a function of M variables.

 > parcoord:=[r,a,b,c,d];

The parametrization of the ball, with center origin, in 5 dimension is the following.

 > p[1]:=(r,a,b,c,d)->r*sin(a)*sin(b)*sin(c)*sin(d); p[2]:=(r,a,b,c,d)->r*sin(a)*sin(b)*sin(c)*cos(d); p[3]:=(r,a,b,c,d)->r*sin(a)*sin(b)*cos(c); p[4]:=(r,a,b,c,d)->r*sin(a)*cos(b); p[5]:=(r,a,b,c,d)->r*cos(a);

Input
parcordb
: List, which contains the name of the coordinates of the manifold G, it contains M-1 symbols.
pb[i]
: Parametrization of the manifold G, the index i runs from 1 to N, and pb[i] is a function of M-1 variables.

 > parcoordb:=[a,b,c,d];

The parametrization of the sphere, with radius and center origin, in 5 dimension is the following.

 > pb[1]:=(a,b,c,d)->rho*sin(a)*sin(b)*sin(c)*sin(d); pb[2]:=(a,b,c,d)->rho*sin(a)*sin(b)*sin(c)*cos(d); pb[3]:=(a,b,c,d)->rho*sin(a)*sin(b)*cos(c); pb[4]:=(a,b,c,d)->rho*sin(a)*cos(b); pb[5]:=(a,b,c,d)->rho*cos(a);

 >

Input

coord: The coordinates of the vector space V, it contsins N symbols.

f[,,...,]: The components of the function f, < <...<

 > coord:=[x,y,z,u,v];

 > f[1,2,3,4]:=(x,y,z,u,v)->alpha*(x^3+y^3+z^3+u^3+v^3); f[1,2,3,5]:=(x,y,z,u,v)->beta*(x+y+z+u+v); f[1,2,4,5]:=(x,y,z,u,v)->x*y^2*z^4; f[1,3,4,5]:=(x,y,z,u,v)->y^2*z; f[2,3,4,5]:=(x,y,z,u,v)->y^2*u*v;

The integral of the exterior derivative of the function f on the manifold G:

First we create the tensorial form of the function f, using the tensorcreate function from the tensor package.

Then it is easy to compute the exterior derivative of f, using the exterior_diff function of the tensor package.

Tensorial form of the function f is tens.
The components of the exterior derivative of the function
f are in exttens.

 > L:=[seq(1..N,i=1..M-1)]: tensorcreate:=array(antisymmetric, op(L)): listtype:=[seq(-1,i=1..M-1)]: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then tensorcreate[op(zz)]:=f[op(zz)](op(coord)): end if: end do: tens:= create(listtype,eval(tensorcreate)): exttens:=exterior_diff(tens,coord):

One can check the components of exttens.

 > get_compts(exttens):

The vectorial measure of the manifold G is in vectormeasure.

 > for j from 1 to M do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](p[i])(op(parcoord)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=1 then vectormeasure:=vv[1]: else vectormeasure:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M do  vectormeasure:=exterior_prod(vectormeasure,vv[j]):    end do: end if:

One can check the components of vectormeasure.

 > get_compts(vectormeasure):

The product of the exterior derivative of the function and the vectorial measure of the manifold is in summ1.

 > helye:={op([seq( coord[i]=p[i](op(parcoord)) ,i=1..N)])}: summ1:=0: for zz in permute(N,M) do  wperm:=0:  for i from 1 to M-1 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-1: end if:  end do:  if wperm=0 then           summ1:=summ1+subs(helye,get_compts(exttens)[op(zz)])*get_compts(vectormeasure)[op(zz)]:   end if: end do:

One can check the first integrand summ1.

 > summ1:=expand(summ1):

Integrating summ1 over the parameter space, this is StLeft.  (This is the left hand side of Stokes' equation.)

 > StLeft:=int(int(int(int(int(summ1,d=0..2*Pi),c=0..Pi),b=0..Pi),a=0..Pi),r=0..rho);

Integral of the function f on the boundary of the manifold G :

The vectorial measure of the boundary of the manifold G is in vectormeasureb.

 > for j from 1 to M-1 do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](pb[i])(op(parcoordb)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=2 then vectormeasureb:=vv[1]: else vectormeasureb:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M-1 do    vectormeasureb:=exterior_prod(vectormeasureb,vv[j]):    end do: end if:

One can check the components of vectormeasureb.

 > get_compts(vectormeasureb):

The product of the function f and the vectorial measure of the boundary of the manifold G is in summ2.

 > helye:={op([seq( coord[i]=pb[i](op(parcoordb)) ,i=1..N)])}: summ2:=0: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then       summ2:=summ2+subs(helye,f[op(zz)](op(coord)))*get_compts(vectormeasureb)[op(zz)]:  end if: end do:

One can check the second integrand summ2.

 > summ2:=expand(summ2):

Integrating summ2 over the parameter space, this is StRight. (This is the right hand side of Stokes' equation.)

 > StRight:=int(int(int(int(summ2,d=0..2*Pi),c=0..Pi),b=0..Pi),a=0..Pi);

The left hand side of Stokes' equation (StLeft) is equal to the right hand side (StRight).

 > simplify(StLeft-StRight);

 >

Some other examples:

Stokes' Theorem

In a 3 dimensional vector space for a 2 dimensional manifold

 > restart;

 > with(tensor): with(linalg): with(combinat):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the assigned name fibonacci now has a global binding

Warning, the protected name Chi has been redefined and unprotected

Input

N: Dimension of the vector space V.
M
: Dimension of the manifold G.

 > N:=3; M:=2;

Input

parcord: List, which contains the name of the coordinates of the manifold G, it contains M symbols.

p[i]: Parametrization of the manifold G, the index i runs from 1 to N, and p[i] is a function of M variables.

 > parcoord:=[r,phi];

 > p[1]:=(r,phi)->r*cos(phi); p[2]:=(r,phi)->r*sin(phi); p[3]:=(r,phi)->r*cos(phi)^2;

Input
parcordb
: List, which contains the name of the coordinates of the manifold G, it contains M-1 symbols.
pb[i]
: Parametrization of the manifold G, the index i runs from 1 to N, and pb[i] is a function of M-1 variables.

 > parcoordb:=[phi];

 > pb[1]:=(phi)->R*cos(phi); pb[2]:=(phi)->R*sin(phi); pb[3]:=(phi)->R*cos(phi)^2;

Input

coord: The coordinates of the vector space V, it contains N symbols.
f[i]
: The components of the function f.

 > coord:=[x,y,z];

 > f[1]:=(x,y,z)->x^2*y; f[2]:=(x,y,z)->y*z; f[3]:=(x,y,z)->z^2;

The integral of the exterior derivative of the function f on the manifold G:

Tensorial form of the function f is tens.
The components of the exterior derivative of the function
f are in exttens.

 > L:=[seq(1..N,i=1..M-1)]: tensorcreate:=array(antisymmetric, op(L)): listtype:=[seq(-1,i=1..M-1)]: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then tensorcreate[op(zz)]:=f[op(zz)](op(coord)): end if: end do: tens:= create(listtype,eval(tensorcreate)): exttens:=exterior_diff(tens,coord):

One can check the components of exttens.

 > get_compts(exttens):

The vectorial measure of the manifold G is in vectormeasure.

 > for j from 1 to M do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](p[i])(op(parcoord)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=1 then vectormeasure:=vv[1]: else vectormeasure:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M do  vectormeasure:=exterior_prod(vectormeasure,vv[j]):    end do: end if:

One can check the components of vectormeasure.

 > get_compts(vectormeasure):

The product of the exterior derivative of the function and the vectorial measure of the manifold is in summ1.

 > helye:={op([seq( coord[i]=p[i](op(parcoord)) ,i=1..N)])}: summ1:=0: for zz in permute(N,M) do  wperm:=0:  for i from 1 to M-1 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-1: end if:  end do:  if wperm=0 then  summ1:=summ1+subs(helye,get_compts(exttens)[op(zz)])*get_compts(vectormeasure)[op(zz)]:      end if: end do:

One can check the first integrand summ1.

 > summ1:=expand(summ1);

Integrating summ1 over the parameter space, this is StLeft.

 > StLeft:=int(int(summ1,phi=0..2*Pi),r=0..R);

Integral of the function f on the boundary of the manifold G:

The vectorial measure of the boundary of the manifold G is in vectormeasureb.

 > for j from 1 to M-1 do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](pb[i])(op(parcoordb)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=2 then vectormeasureb:=vv[1]: else vectormeasureb:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M-1 do    vectormeasureb:=exterior_prod(vectormeasureb,vv[j]):    end do: end if:

One can check the components of vectormeasureb.

 > get_compts(vectormeasureb):

The product of the function f and the vectorial measure of the boundary of the manifold G is in summ2.

 > helye:={op([seq( coord[i]=pb[i](op(parcoordb)) ,i=1..N)])}: summ2:=0: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then       summ2:=summ2+subs(helye,f[op(zz)](op(coord)))*get_compts(vectormeasureb)[op(zz)]:  end if: end do:

One can check the first integrand summ2.

 > summ2:=expand(summ2):

Integrating summ2 over the parameter space, this is StRight.

 > StRight:=int(summ2,phi=0..2*Pi);

The left hand side of Stokes' equation (StLeft) is equal to the right hand side (StRight).

 > simplify(StLeft-StRight);

 >

Stokes' Theorem

In a 3 dimensional vector space for a 3 dimensional manifold

 > restart;

 > with(tensor): with(linalg): with(combinat):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the assigned name fibonacci now has a global binding

Warning, the protected name Chi has been redefined and unprotected

Input

N: Dimension of the vector space V.
M
: Dimension of the manifold G.

 > N:=3; M:=3;

Input

parcord: List, which contains the name of the coordinates of the manifold G, it contains M symbols.

p[i]: Parametrization of the manifold G, the index i runs from 1 to N, and p[i] is a function of M variables.

 > parcoord:=[r,theta,phi];

 > p[1]:=(r,theta,phi)->r*sin(theta)*cos(phi); p[2]:=(r,theta,phi)->r*sin(theta)*sin(phi); p[3]:=(r,theta,phi)->r*cos(theta);

Input
parcordb
: List, which contains the name of the coordinates of the manifold G, it contains M-1 symbols.
pb[i]
: Parametrization of the manifold G, the index i runs from 1 to N, and pb[i] is a function of M-1 variables.

 > parcoordb:=[theta,phi];

 > pb[1]:=(theta,phi)->R*sin(theta)*cos(phi); pb[2]:=(theta,phi)->R*sin(theta)*sin(phi); pb[3]:=(theta,phi)->R*cos(theta);

Input

coord: The coordinates of the vector space V, it contains N symbols.
f[i,j]
: The components of the function f, i<j.

 > coord:=[x,y,z];

 > f[1,2]:=(x,y,z)->y^2*z; f[1,3]:=(x,y,z)->x^3+z^2; f[2,3]:=(x,y,z)->x^2*y^2*z;

The integral of the exterior derivative of the function f on the manifold G:

Tensorial form of the function f is tens.
The components of the exterior derivative of the function
f are in exttens.

 > L:=[seq(1..N,i=1..M-1)]: tensorcreate:=array(antisymmetric, op(L)): listtype:=[seq(-1,i=1..M-1)]: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then tensorcreate[op(zz)]:=f[op(zz)](op(coord)): end if: end do: tens:= create(listtype,eval(tensorcreate)): exttens:=exterior_diff(tens,coord):

One can check the components of  exttens.

 > get_compts(exttens):

The vectorial measure of the manifold G is in vectormeasure.

 > for j from 1 to M do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](p[i])(op(parcoord)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=1 then vectormeasure:=vv[1]: else vectormeasure:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M do  vectormeasure:=exterior_prod(vectormeasure,vv[j]):    end do: end if:

One can check the components of vectormeasure.

 > get_compts(vectormeasure):

The product of the exterior derivative of the function and the vectorial measure of the manifold is in summ1.

 > helye:={op([seq( coord[i]=p[i](op(parcoord)) ,i=1..N)])}: summ1:=0: for zz in permute(N,M) do  wperm:=0:  for i from 1 to M-1 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-1: end if:  end do:  if wperm=0 then  summ1:=summ1+subs(helye,get_compts(exttens)[op(zz)])*get_compts(vectormeasure)[op(zz)]:          end if: end do:

One can check the first integrand summ1.

 > summ1:=expand(summ1):

Integrating summ1 over the parameter space, this is StLeft.

 > StLeft:=int(int(int(summ1,phi=0..2*Pi),theta=0..Pi),r=0..R);

Integral of the function f on the boundary of the manifold G:

The vectorial measure of the boundary of the manifold G is in vectormeasureb.

 > for j from 1 to M-1 do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](pb[i])(op(parcoordb)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=2 then vectormeasureb:=vv[1]: else vectormeasureb:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M-1 do    vectormeasureb:=exterior_prod(vectormeasureb,vv[j]):    end do: end if:

One can check the components of vectormeasureb.

 > get_compts(vectormeasureb):

The product of the function f and the vectorial measure of the boundary of the manifold G is in summ2.

 > helye:={op([seq( coord[i]=pb[i](op(parcoordb)) ,i=1..N)])}: summ2:=0: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then       summ2:=summ2+subs(helye,f[op(zz)](op(coord)))*get_compts(vectormeasureb)[op(zz)]:  end if: end do:

One can check the second integrand summ2.

 > summ2:=expand(summ2):

Integrating summ2 over the parameter space, this is StRight.

 > StRight:=int(int(summ2,phi=0..2*Pi),theta=0..Pi);

The left hand side of Stokes' equation (StLeft) is equal to the right hand side (StRight).

 > simplify(StLeft-StRight);

 >

Stokes' Theorem

In a 4 dimensional vector space for a 2 dimensional manifold

 > restart;

 > with(tensor): with(linalg): with(combinat):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the assigned name fibonacci now has a global binding

Warning, the protected name Chi has been redefined and unprotected

Input

N: Dimension of the vector space V.
M
: Dimension of the manifold G.

 > N:=4; M:=2;

Input

parcord: List, which contains the name of the coordinates of the manifold G, it contains M symbols.

p[i]: Parametrization of the manifold G, the index i runs from 1 to N, and p[i] is a function of M variables.

 > parcoord:=[r,phi];

 > p[1]:=(r,phi)->r*cos(phi); p[2]:=(r,phi)->r*sin(phi); p[3]:=(r,phi)->r^2*cos(2*phi); p[4]:=(r,phi)->r^2;

Input
parcordb
: List, which contains the name of the coordinates of the manifold G, it contains M-1 symbols.
pb[i]
: Parametrization of the manifold G, the index i runs from 1 to N, and pb[i] is a function of M-1 variables.

 > parcoordb:=[phi];

 > pb[1]:=(phi)->R*cos(phi); pb[2]:=(phi)->R*sin(phi); pb[3]:=(phi)->R^2*cos(2*phi); pb[4]:=(phi)->R^2;

Input

coord: The coordinates of the vector space V, it contains N symbols.

f[i]: The components of the function f.

 > coord:=[x,y,z,v];

 > f[1]:=(x,y,z,v)->y^2*z*v; f[2]:=(x,y,z,v)->x^3+z^2*v^2; f[3]:=(x,y,z,v)->x*y^2*z^4; f[4]:=(x,y,z,v)->x^2*y^2*z;

The integral of the exterior derivative of the function f on the manifold G:

Tensorial form of the function f is tens.
The components of the exterior derivative of the function
f are in exttens.

 > L:=[seq(1..N,i=1..M-1)]: tensorcreate:=array(antisymmetric, op(L)): listtype:=[seq(-1,i=1..M-1)]: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then tensorcreate[op(zz)]:=f[op(zz)](op(coord)): end if: end do: tens:= create(listtype,eval(tensorcreate)): exttens:=exterior_diff(tens,coord):

One can check the components of exttens.

 > get_compts(exttens):

The vectorial measure of the manifold G is in vectormeasure.

 > for j from 1 to M do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](p[i])(op(parcoord)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=1 then vectormeasure:=vv[1]: else vectormeasure:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M do  vectormeasure:=exterior_prod(vectormeasure,vv[j]):    end do: end if:

One can check the components of vectormeasure.

 > get_compts(vectormeasure):

The product of the exterior derivative of the function and the vectorial measure of the manifold is in summ1.

 > helye:={op([seq( coord[i]=p[i](op(parcoord)) ,i=1..N)])}: summ1:=0: for zz in permute(N,M) do  wperm:=0:  for i from 1 to M-1 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-1: end if:  end do:  if wperm=0 then  summ1:=summ1+subs(helye,get_compts(exttens)[op(zz)])*get_compts(vectormeasure)[op(zz)]:      end if: end do:

One can check the first integrand summ1.

 > summ1:=expand(summ1):

Integrating summ1 over the parameter space, this is StLeft.

 > StLeft:=int(int(int(summ1,phi=0..2*Pi),theta=0..Pi),r=0..R);

Integral of the function f on the boundary of the manifold G:

The vectorial measure of the boundary of the manifold G is in vectormeasureb.

 > for j from 1 to M-1 do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](pb[i])(op(parcoordb)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=2 then vectormeasureb:=vv[1]: else vectormeasureb:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M-1 do    vectormeasureb:=exterior_prod(vectormeasureb,vv[j]):    end do: end if:

One can check the components of vectormeasureb.

 > get_compts(vectormeasureb):

The product of the function f and the vectorial measure of the boundary of the manifold G is in summ2.

 > helye:={op([seq( coord[i]=pb[i](op(parcoordb)) ,i=1..N)])}: summ2:=0: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then       summ2:=summ2+subs(helye,f[op(zz)](op(coord)))*get_compts(vectormeasureb)[op(zz)]:  end if: end do:

One can check the second integrand summ2.

 > summ2:=expand(summ2):

Integrating summ2 over the parameter space, this is StRight.

 > StRight:=int(int(summ2,phi=0..2*Pi),theta=0..Pi);

The left hand side of Stokes' equation (StLeft) is equal to the right hand side (StRight).

 > simplify(StLeft-StRight);

 >

Stokes' Theorem

In a 4 dimensional vector space for a 3 dimensional manifold

 > restart;

 > with(tensor): with(linalg): with(combinat):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the assigned name fibonacci now has a global binding

Warning, the protected name Chi has been redefined and unprotected

Input

N: Dimension of the vector space V.
M
: Dimension of the manifold G.

 > N:=4; M:=3;

Input

parcord: List, which contains the name of the coordinates of the manifold G, it contains M symbols.

p[i]: Parametrization of the manifold G, the index i runs from 1 to N, and p[i] is a function of M variables.

 > parcoord:=[r,theta,phi];

 > p[1]:=(r,theta,phi)->r*sin(theta)*cos(phi); p[2]:=(r,theta,phi)->r*sin(theta)*sin(phi); p[3]:=(r,theta,phi)->r*cos(theta); p[4]:=(r,theta,phi)->r*cos(theta)^2;

Input
parcordb
: List, which contains the name of the coordinates of the manifold G, it contains M-1 symbols.
pb[i]
: Parametrization of the manifold G, the index i runs from 1 to N, and pb[i] is a function of M-1 variables.

 > parcoordb:=[theta,phi];

 > pb[1]:=(theta,phi)->R*sin(theta)*cos(phi); pb[2]:=(theta,phi)->R*sin(theta)*sin(phi); pb[3]:=(theta,phi)->R*cos(theta); pb[4]:=(theta,phi)->R*cos(theta)^2;

Input

coord: The coordinates of the vector space V, it contains N symbols.
f[i,j]
: The components of the function f, i<j.

 > coord:=[x,y,z,v];

 > f[1,2]:=(x,y,z,v)->y^2*z*v; f[1,3]:=(x,y,z,v)->x^3+z^2*v^2; f[1,4]:=(x,y,z,v)->x*y^2*z^4; f[2,3]:=(x,y,z,v)->x^2*y^2*z; f[2,4]:=(x,y,z,v)->x^3-2*z^2*v; f[3,4]:=(x,y,z,v)->x^4*y^2*z^2;

The integral of the exterior derivative of the function f on the manifold G:

Tensorial form of the function f is tens.
The components of the exterior derivative of the function
f are in exttens.

 > L:=[seq(1..N,i=1..M-1)]: tensorcreate:=array(antisymmetric, op(L)): listtype:=[seq(-1,i=1..M-1)]: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then tensorcreate[op(zz)]:=f[op(zz)](op(coord)): end if: end do: tens:= create(listtype,eval(tensorcreate)): exttens:=exterior_diff(tens,coord):

One can check the components of exttens.

 > get_compts(exttens):

The vectorial measure of the manifold G is in vectormeasure.

 > for j from 1 to M do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](p[i])(op(parcoord)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=1 then vectormeasure:=vv[1]: else vectormeasure:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M do  vectormeasure:=exterior_prod(vectormeasure,vv[j]):    end do: end if:

One can check the components of vectormeasure.

 > get_compts(vectormeasure):

The product of the exterior derivative of the function and the vectorial measure of the manifold is in summ1.

 > helye:={op([seq( coord[i]=p[i](op(parcoord)) ,i=1..N)])}: summ1:=0: for zz in permute(N,M) do  wperm:=0:  for i from 1 to M-1 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-1: end if:  end do:  if wperm=0 then  summ1:=summ1+subs(helye,get_compts(exttens)[op(zz)])*get_compts(vectormeasure)[op(zz)]:      end if: end do:

One can check the first integrand summ1.

 > summ1:=expand(summ1):

Integrating summ1 over the parameter space, this is StLeft.

 > StLeft:=int(int(int(summ1,phi=0..2*Pi),theta=0..Pi),r=0..R);

Integral of the function f on the boundary of the manifold G:

The vectorial measure of the boundary of the manifold G is in vectormeasureb.

 > for j from 1 to M-1 do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](pb[i])(op(parcoordb)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=2 then vectormeasureb:=vv[1]: else vectormeasureb:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M-1 do    vectormeasureb:=exterior_prod(vectormeasureb,vv[j]):    end do: end if:

One can check the components of vectormeasureb.

 > get_compts(vectormeasureb):

The product of the function f and the vectorial measure of the boundary of the manifold G is in summ2.

 > helye:={op([seq( coord[i]=pb[i](op(parcoordb)) ,i=1..N)])}: summ2:=0: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then       summ2:=summ2+subs(helye,f[op(zz)](op(coord)))*get_compts(vectormeasureb)[op(zz)]:  end if: end do:

One can check the second integrand summ2.

 > summ2:=expand(summ2):

Integrating summ2 over the parameter space, this is StRight.

 > StRight:=int(int(summ2,phi=0..2*Pi),theta=0..Pi);

The left hand side of Stokes' equation (StLeft) is equal to the right hand side (StRight).

 > simplify(StLeft-StRight);

 >

Stokes' Theorem

In a 4 dimensional vector space for a 4 dimensional manifold

 > restart;

 > with(tensor): with(linalg): with(combinat):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the assigned name fibonacci now has a global binding

Warning, the protected name Chi has been redefined and unprotected

Input

N: Dimension of the vector space V.
M
: Dimension of the manifold G.

 > N:=4; M:=4;

Input

parcord: List, which contains the name of the coordinates of the manifold G, it contains M symbols.

p[i]: Parametrization of the manifold G, the index i runs from 1 to N, and p[i] is a function of M variables.

 > parcoord:=[r,a,b,c];

 > p[1]:=(r,a,b,c)->r*sin(a)*sin(b)*sin(c); p[2]:=(r,a,b,c)->r*sin(a)*sin(b)*cos(c); p[3]:=(r,a,b,c)->r*sin(a)*cos(b); p[4]:=(r,a,b,c)->r*cos(a);

Input
parcordb
: List, which contains the name of the coordinates of the manifold G, it contains M-1 symbols.
pb[i]
: Parametrization of the manifold G, the index i runs from 1 to N, and pb[i] is a function of M-1 variables.

 > parcoordb:=[a,b,c];

 > pb[1]:=(a,b,c)->R*sin(a)*sin(b)*sin(c); pb[2]:=(a,b,c)->R*sin(a)*sin(b)*cos(c); pb[3]:=(a,b,c)->R*sin(a)*cos(b); pb[4]:=(a,b,c)->R*cos(a);

Input

coord: The coordinates of the vector space V, it contains N symbols.
f[i,j,k]
: The components of the function f, i<j<k.

 > coord:=[x,y,z,v];

 > f[1,2,3]:=(x,y,z,v)->alpha*z^2; f[1,2,4]:=(x,y,z,v)->beta*(x+y+z+v); f[1,3,4]:=(x,y,z,v)->gamma*(x^3+y^3+z^3+v^3); f[2,3,4]:=(x,y,z,v)->delta*(x^5+z^5);

The integral of the exterior derivative of the function f on the manifold G:

Tensorial form of the function f is tens.
The components of the exterior derivative of the function
f are in exttens.

 > L:=[seq(1..N,i=1..M-1)]: tensorcreate:=array(antisymmetric, op(L)): listtype:=[seq(-1,i=1..M-1)]: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then tensorcreate[op(zz)]:=f[op(zz)](op(coord)): end if: end do: tens:= create(listtype,eval(tensorcreate)): exttens:=exterior_diff(tens,coord):

One can check the components of exttens.

 > get_compts(exttens):

The vectorial measure of the manifold G is in vectormeasure.

 > for j from 1 to M do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](p[i])(op(parcoord)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=1 then vectormeasure:=vv[1]: else vectormeasure:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M do  vectormeasure:=exterior_prod(vectormeasure,vv[j]):    end do: end if:

One can check the components of vectormeasure.

 > get_compts(vectormeasure):

The product of the exterior derivative of the function and the vectorial measure of the manifold is in summ1.

 > helye:={op([seq( coord[i]=p[i](op(parcoord)) ,i=1..N)])}: summ1:=0: for zz in permute(N,M) do  wperm:=0:  for i from 1 to M-1 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-1: end if:  end do:  if wperm=0 then  summ1:=summ1+subs(helye,get_compts(exttens)[op(zz)])*get_compts(vectormeasure)[op(zz)]:      end if: end do:

One can check the first integrand summ1.

 > summ1:=expand(summ1):

Integrating summ1 over the parameter space, this is StLeft.

 > StLeft:=int(int(int(int(summ1,c=0..2*Pi),b=0..Pi),a=0..Pi),r=0..R);

Integral of the function f on the boundary of the manifold G:

The vectorial measure of the boundary of the manifold G is in vectormeasureb.

 > for j from 1 to M-1 do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](pb[i])(op(parcoordb)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=2 then vectormeasureb:=vv[1]: else vectormeasureb:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M-1 do    vectormeasureb:=exterior_prod(vectormeasureb,vv[j]):    end do: end if:

One can check the components of vectormeasureb.

 > get_compts(vectormeasureb):

The product of the function f and the vectorial measure of the boundary of the manifold G is in summ2.

 > helye:={op([seq( coord[i]=pb[i](op(parcoordb)) ,i=1..N)])}: summ2:=0: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then       summ2:=summ2+subs(helye,f[op(zz)](op(coord)))*get_compts(vectormeasureb)[op(zz)]:  end if: end do:

One can check the second integrand summ2.

 > summ2:=expand(summ2):

Integrating summ2 over the parameter space, this is StRight.

 > StRight:=int(int(int(summ2,c=0..2*Pi),b=0..Pi),a=0..Pi);

The left hand side of Stokes' equation (StLeft) is equal to the right hand side (StRight).

 > simplify(StLeft-StRight);

 >

Stokes' Theorem

In a 6 dimensional vector space for a 4 dimensional manifold

In this case we consider a 4 dimensional manifold in a 6 dimensional Euclidean space, and a function f, detailed below.

 > restart;

 > with(tensor): with(linalg): with(combinat):

Warning, the protected names norm and trace have been redefined and unprotected

Warning, the assigned name fibonacci now has a global binding

Warning, the protected name Chi has been redefined and unprotected

Input

N: Dimension of the vector space V.
M
: Dimension of the manifold G.

 > N:=6; M:=4;

Input

parcord: List, which contains the name of the coordinates of the manifold G, it contains M symbols.

p[i]: Parametrization of the manifold G, the index i runs from 1 to N, and p[i] is a function of M variables.

 > parcoord:=[r,a,b,c];

 > p[1]:=(r,a,b,c)->r*sin(a)*sin(b)*sin(c); p[2]:=(r,a,b,c)->r*sin(a)*sin(b)*cos(c); p[3]:=(r,a,b,c)->r*sin(a)*cos(b); p[4]:=(r,a,b,c)->r*cos(a); p[5]:=(r,a,b,c)->r^2*cos(2*c); p[6]:=(r,a,b,c)->r^4;

Input
parcordb
: List, which contains the name of the coordinates of the manifold G, it contains M-1 symbols.
pb[i]
: Parametrization of the manifold G, the index i runs from 1 to N, and pb[i] is a function of M-1 variables.

 > parcoordb:=[a,b,c];

 > pb[1]:=(a,b,c)->R*sin(a)*sin(b)*sin(c); pb[2]:=(a,b,c)->R*sin(a)*sin(b)*cos(c); pb[3]:=(a,b,c)->R*sin(a)*cos(b); pb[4]:=(a,b,c)->R*cos(a); pb[5]:=(a,b,c)->R^2*cos(2*c); pb[6]:=(a,b,c)->R^4;

Input

coord: The coordinates of the vector space V, it contains N symbols.

f[i,j,k]:  The components of the function f, i<j<k.

 > coord:=[x,y,z,u,v,w];

 > f[1,2,3]:=(x,y,z,u,v,w)->alpha*(x^3+y^3+z^3+u^3+v^3+w^3); f[1,2,4]:=(x,y,z,u,v,w)->u^5+w^3+v^3; f[1,2,5]:=(x,y,z,u,v,w)->x*y^2*z^4; f[1,2,6]:=(x,y,z,u,v,w)->w^2*y^2*z; f[1,3,4]:=(x,y,z,u,v,w)->y^2*u*v; f[1,3,5]:=(x,y,z,u,v,w)->u^3+z^2*v^2; f[1,3,6]:=(x,y,z,u,v,w)->y^2*z^4; f[1,4,5]:=(x,y,z,u,v,w)->w^2*z; f[1,4,6]:=(x,y,z,u,v,w)->w*u*v^4; f[1,5,6]:=(x,y,z,u,v,w)->x^2*y^2*z; f[2,3,4]:=(x,y,z,u,v,w)->u^2*w*v; f[2,3,5]:=(x,y,z,u,v,w)->4*x^2*v^2; f[2,3,6]:=(x,y,z,u,v,w)->w^2*y^4; f[2,4,5]:=(x,y,z,u,v,w)->u^2*v^2*x*z; f[2,4,6]:=(x,y,z,u,v,w)->x^5+y^5+z^5+u^5+v^5+w^5; f[2,5,6]:=(x,y,z,u,v,w)->x^2*y^2*z^2*u^2; f[3,4,5]:=(x,y,z,u,v,w)->x^2*y^2*z*v; f[3,4,6]:=(x,y,z,u,v,w)->x*y^2*z^4*u^2*w^2; f[3,5,6]:=(x,y,z,u,v,w)->x^2*u^2; f[4,5,6]:=(x,y,z,u,v,w)->w^2*u^2*x*z;

The integral of the exterior derivative of the function f on the manifold G:

Tensorial form of the function f is tens.
The components of the exterior derivative of the function
f are in exttens.

 > L:=[seq(1..N,i=1..M-1)]: tensorcreate:=array(antisymmetric, op(L)): listtype:=[seq(-1,i=1..M-1)]: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then tensorcreate[op(zz)]:=f[op(zz)](op(coord)): end if: end do: tens:= create(listtype,eval(tensorcreate)): exttens:=exterior_diff(tens,coord):

One can check the components of exttens.

 > get_compts(exttens):

The vectorial measure of the manifold G is in vectormeasure.

 > for j from 1 to M do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](p[i])(op(parcoord)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=1 then vectormeasure:=vv[1]: else vectormeasure:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M do  vectormeasure:=exterior_prod(vectormeasure,vv[j]):    end do: end if:

One can check the components of vectormeasure.

 > get_compts(vectormeasure):

The product of the exterior derivative of the function and the vectorial measure of the manifold is in summ1.

 > helye:={op([seq( coord[i]=p[i](op(parcoord)) ,i=1..N)])}: summ1:=0: for zz in permute(N,M) do  wperm:=0:  for i from 1 to M-1 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-1: end if:  end do:  if wperm=0 then       summ1:=summ1+subs(helye,get_compts(exttens)[op(zz)])*get_compts(vectormeasure)[op(zz)]:  end if: end do:

One can check the first integrand summ1.

 > summ1:=expand(summ1):

Integrating summ1 over the parameter space, this is StLeft.

 > StLeft:=int(int(int(int(summ1,c=0..2*Pi),b=0..Pi),a=0..Pi),r=0..R);

Integral of the function f on the boundary of the manifold G:

The vectorial measure of the boundary of the manifold G is in vectormeasureb.

 > for j from 1 to M-1 do  vparcderiv:=array(1..N):  for i from 1 to N do    vparcderiv[i]:=D[j](pb[i])(op(parcoordb)):  end do;  vv[j]:= create([-1],eval(vparcderiv)); end do: if M=2 then vectormeasureb:=vv[1]: else vectormeasureb:=exterior_prod(vv[1],vv[2]): end if: if M>2 then  for j from 3 to M-1 do    vectormeasureb:=exterior_prod(vectormeasureb,vv[j]):    end do: end if:

One can check the components of vectormeasureb.

 > get_compts(vectormeasureb):

The product of the function f and the vectorial measure of the boundary of the manifold G is in summ2.

 > helye:={op([seq( coord[i]=pb[i](op(parcoordb)) ,i=1..N)])}: summ2:=0: for zz in permute(N,M-1) do  wperm:=0:  for i from 1 to M-2 do    if zz[i]>zz[i+1] then wperm:=1: i:=M-2: end if:  end do:  if wperm=0 then       summ2:=summ2+subs(helye,f[op(zz)](op(coord)))*get_compts(vectormeasureb)[op(zz)]:  end if: end do:

One can check the second integrand summ2.

 > summ2:=expand(summ2):

Integrating summ2 over the parameter space, this is StRight.

 > StRight:=int(int(int(summ2,c=0..2*Pi),b=0..Pi),a=0..Pi);

The left hand side of Stokes' equation (StLeft) is equal to the right hand side (StRight).

 > simplify(StLeft-StRight);

 >

Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.