lineintvec.mws

Line Integrals of Vector Fields

Using Maple and the vec_calc Package

This worksheet shows how to compute line integrals of vector fields using Maple and the vec_calc package. As examples we compute

* The Work Done by an Electric Field

* The Circulation of a Fluid

To start the vec_calc package, execute the following commands:

> restart;

> libname:=libname,"C:/mylib/vector";

libname :=

> with(vec_calc): vc_aliases:

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

Warning, the name changecoords has been redefined

Package:   vec_calc   Version 4.3

For all HELP, execute: ?vec_calc

To use aliases, execute:   vc_aliases;

>

The Work Done by an Electric Field

The electric field of a line of charge with charge density lambda is E = [2*k*lambda*x/sqrt(x^2+y^2), 2*k*lambda*y/sqrt(... where k is a constant. A particle of charge q moves through this field along the line segment from [1, 2, 3] to [3, 2, 1] . We want to find the work done by this electric field on the charged particle.

We input the field as the function:

> E:=MF([x,y,z],[2*k*lambda*x/sqrt(x^2+y^2),2*k*lambda*y/sqrt(x^2+y^2),0]);

E := [proc (x, y, z) options operator, arrow; 2*k*l...

We input the line segment as

> r:=MF(t, evall([1,2,3]+t*([3,2,1]-[1,2,3])));

r := [proc (t) options operator, arrow; 1+2*t end p...

where 0 <= t ` ` <= 1 . So the velocity is

> v:=D(r);

v := [2, 0, -2]

On the line segment, the electric field is

> Er:=E(op(r(t)));

Er := [2*k*lambda*(1+2*t)/(sqrt((1+2*t)^2+4)), 4*k*...

The work is defined as Work = Int(q*E*`.`,r) = Int(q*E(r(t))*`.`*v(t),t = 0 .. 1) . Consequently,

> qEv:=q*Er &. v(t);

qEv := 4*q*k*lambda*(1+2*t)/(sqrt(5+4*t+4*t^2))

> Work:=Int(qEv,t=0..1); Work:=value(%);

Work := Int(4*q*k*lambda*(1+2*t)/(sqrt(5+4*t+4*t^2)...

Work := 2*sqrt(13)*q*k*lambda-2*sqrt(5)*q*k*lambda

Another way to compute this line integral is to use the Line_int_vector command (or its alias Liv ) from the vec_calc package which works directly with the parametrized curve and the vector field:

> Liv(E,r,t=0..1); Work:=q*value(%);

Int(4*k*lambda*(1+2*t)/(sqrt(5+4*t+4*t^2)),t = 0 .....

Work := q*(2*sqrt(13)*k*lambda-2*sqrt(5)*k*lambda)

There is a second way to compute this work. The electric field is conservative because it is curl-free:

> CURL(E);

[0, 0, 0]

So the electric field has a scalar potential, phi .

> POT(E,'phi');

true

> phi(x,y,z);

2*k*lambda*sqrt(x^2+y^2)

By the Fundamental Theorem of Calculus, the work is the change in the potential energy:

> Work:=q*phi(3,2,1)-q*phi(1,2,3);

Work := 2*sqrt(13)*q*k*lambda-2*sqrt(5)*q*k*lambda

>

The Circulation of a Fluid

The velocity of the water in a sink going down the drain is V = [(-y-z)/(x^2+y^2), (x-z)/(x^2+y^2), z^2*(-x-y)/... . We want to find the circulation of the fluid counterclockwise around the circle x^2+y^2 = 4 with z = 2 .

We enter the fluid velocity as a function:

> V:=MF([x,y,z],[(-y-z)/(x^2+y^2), (x-z)/(x^2+y^2), z^2*(-x-y)/((x^2+y^2)^2)]);

V := [proc (x, y, z) options operator, arrow; (-y-z...

The circle may be parametrized as

> r:=MF(t,[2*cos(t),2*sin(t),3]);

r := [proc (t) options operator, arrow; 2*cos(t) en...

Its tangent vector (velocity) is:

> v:=D(r);

v := [proc (t) options operator, arrow; -2*sin(t) e...

Caution: Don't confuse the velocity (tangent vector) of the curve v with the velocity of the fluid V .

On the curve, the fluid velocity becomes:

> V(op(r(t))); Vr:=simplify(%);

[(-2*sin(t)-3)/(4*cos(t)^2+4*sin(t)^2), (2*cos(t)-3...

Vr := [-1/2*sin(t)-3/4, 1/2*cos(t)-3/4, -9/8*cos(t)...

The circulation is defined as Circ = Int(V*`.`,r) = Int(V(r(t))*`.`*v(t),t = 0 .. 2*Pi) . Consequently,

> Vr_v:=Vr &. v(t);

Vr_v := 3/2*sin(t)-3/2*cos(t)+1

> Circ:=Int(Vr_v,t=0..2*Pi); Circ:=value(%);

Circ := Int(3/2*sin(t)-3/2*cos(t)+1,t = 0 .. 2*Pi)

Circ := 2*Pi

Another way to compute this line integral is to use the Line_int_vector command (or its alias Liv ) from the vec_calc package which works directly with the parametrized curve and the vector field:

> Liv(V,r,t=0..2*Pi); Circ:=value(%);

Int(3/2*sin(t)-3/2*cos(t)+1,t = 0 .. 2*Pi)

Circ := 2*Pi

>