Computing Line Integrals \302\251 2006 Mike May, S.J.- maymk@slu.edu When working with line integrals, we want to use the Student[VectorCalculus] package. It has nice commands to evaluate line integrals. To help our understanding, it seems worthwhile to go through using Maple to set up and evaluate line integrals over a parameterized curve in a step by step process, labeling all the intermediate steps. We will then produce new procedures that do everything in one command. We then note the Student[VectorCalculus] package commands that give the answer. We also want to set some technical conditions, specifying that the vector fields will be written as vectors rather than as linear combinations of basis vectors. restart: with(Student[VectorCalculus]); BasisFormat(false):
<Text-field style="Heading 2" layout="Heading 2">A step by step example</Text-field> First we need to define a vector field that we want to integrate, the parameterized path we are integrating over, and the limits on the parameter. For our example we will use the familiar circular vector field and integrate over half an ellipse. F := <-y,x>; VF := VectorField(F); C := <3*cos(2*t), 2*sin(2*t)>; trange := t=0..Pi/2; The process of integrating the line integral over the parameterized curve can be broken into 6 steps: 1) Plot a graph of the vector field and the parameterized curve. 2) Substitute the parameterization of the path into the field to make the field a vector valued function of the parameter. 3) Take the derivative of the path with respect to the parameter. 4) Evaluate the dot product and simplify. This reduces the problem to an integral over an interval. 5) Set up the line integral with the integrand being the dot product of the vector field and the derivative of the parameterized path. 6) Evaluate the integral. We are ready to walk through the steps one at a time. As we work through the example with Maple, you should make sure that you can also do each step by hand. The first step is to look at a graph of the vector field and the parameterized curve. P1 := VectorField(F, output=plot,view=[-4..4,-1..4], color=red): P2 := SpaceCurve(C,trange, color=blue): plots[display]({P1,P2}, axes=boxed, scaling =constrained); The second step is to replace x and y and the vector field with the parameterizations of x and y at the appropriate point on the path. FonC := evalVF(VF,C); The third step is to take the derivative of the parameterized path. R := diff(C,t); The fourth step is to evaluate the dot product in the integrand and simplify. integrand1 := FonC.R; integrand := simplify(integrand1): print("The integrand is ", integrand); The next step is to set up the line integral Int(integrand, trange); Which we now evaluate the integral and evaluate the result numerically if needed. intval := int(integrand, trange); evalf(intval);
<Text-field style="Heading 2" layout="Heading 2">An automated approach</Text-field> For convenience we block the code into two procedures we can use, one for plotting, and one for setting up the integral and evaluating. This allows us to modify the problem with a minimal amount of work. pathplot := proc(vecfield, path, trange, window) local vfieldplot, parampath; vfieldplot := VectorField(vecfield,output=plot,view=window): parampath := SpaceCurve(path,trange, color=black): plots[display]({vfieldplot, parampath}); end: lineintegral:= proc(vecfield, path, trange) local intval, paramfield, dpath, integrand; print("the vector field is ", vecfield); print("the path is ", path, " with ", trange); print(Int((vecfield.Diff(path,t)), trange)); paramfield := evalVF(VectorField(vecfield), path); print("the funtion on the path is ", paramfield); print(Int((paramfield.Diff(path,t)), trange)); dpath := diff(path, t); print("the derivative of the path is ", diff(path, t)); print(Int((paramfield.dpath), trange)); integrand := simplify(paramfield.dpath): print("The integrand is ", integrand); print(Int(integrand, trange)); intval := int(integrand, trange); print("the integral is ", intval); print(evalf(intval)); end: Thus, we can get the results by entering the vectorfield and path and executing the two commands. SetCoordinates( cartesian[x,y] ): vfield := <-y,x>; path := <1+3*cos(t), -4+2*sin(t)>; trange := t=0..Pi; pathplot(vfield, path, trange, [-5..5, -5..5]); lineintegral(vfield, path, trange); It should be noted, that if all we want is the final answer, the VectorCalculus package has a LineInt command that can be used to plot the curve and field, set up the integral, and give the final answer. LineInt(VectorField(vfield), Path(path, trange),output=plot); LineInt(VectorField(vfield), Path(path, trange),output=integral); LineInt(VectorField(vfield), Path(path, trange));
<Text-field style="Heading 2" layout="Heading 2">Exercises:</Text-field> 1) Evaluate the line integral where F = [ln(y), ln(x)] and C is the curve given parametrically by [2t, t^2] with t=2..4. 2) Evaluate the line integral where F = [2y, -sin(y)] and C is the unit circle traced in a counterclockwise directions from the point (1, 0). 3) Evaluate the line integral where F = e^x i + e^y j and C is the part of the ellipse x^2 + 4y^2 = 4 from the point (0, 1) to the point (2, 0) in a clockwise direction.
<Text-field style="Heading 2" layout="Heading 2">Line Integrals in 3-D</Text-field> If the vector field is in three dimensions, we need to slightly modify the lineinegral command. In that case we will not plot the curve. lineintegral3d:= proc(vecfield, path, trange) local intval, paramfield, dpath, integrand; print("the vector field ", vecfield); print("the path ", path, " with ", trange); print(Int((vecfield.Diff(path,t)), trange)); paramfield := evalVF(VectorField(vecfield), path); print("the funtion on the path is ", paramfield); print(Int((paramfield.Diff(path,t)), trange)); dpath := diff(path, t); print("the derivative of the path is ", diff(path, t)); print(Int((paramfield.dpath), trange)); integrand := simplify(paramfield.dpath): print("The integrand is ", integrand); print(Int(integrand, trange)); intval := int(integrand, trange); print("the integral is ", intval); print(evalf(intval)); end: Using this command we redo example 4 from the book. Note that we have to specify that we are changing the coordinate system. (To go back to 2D we will need use SetCoordinates( cartesian[x,y]): ) SetCoordinates( cartesian[x,y,z] ): vfield := <x, z, -x*y>; path := <cos(t), sin(t), 2*t>; trange := t=0..3*Pi; lineintegral3d(vfield, path, trange); Once again, if all we want is the final answer, the VectorCalculus package has a LineInt command. LineInt(VectorField(vfield), Path(path, trange), output=plot); LineInt(VectorField(vfield), Path(path, trange), output=integral); LineInt(VectorField(vfield), Path(path, trange));
<Text-field style="Heading 2" layout="Heading 2">Exercise:</Text-field> 4) Evaluate the line integral where F = -y i + x j + 5 k and C is the helix [cos(t), sin(t) t] for t=0..4Pi.