\( \DeclareMathOperator{\abs}{abs} \newcommand{\ensuremath}[1]{\mbox{$#1$}} \)

Line and Path Integrals

 1 Line Integrals

Suppose that we have a vector curve C described by r(t)=[x(t),y(t),z(t)], and we would like to find the
integral of the scalar function f(x,y,z) over the curve C (where a < t < b).

There are *many* ways to do this, but we will follow the most efficient.  Since we are going to need the
magnitude of a vector (to compute ds), we define:

(%i1) mag(u):=sqrt(u.u);
\[\tag{%o1} \operatorname{mag}(u):=\sqrt{u\mathit{ . }u}\]

Now suppose that the function we want to integrate is simply f(x,y)=x^2 and the curve that we
want to integrate over is the circle: x(t)=sqrt(t) and y(t)=t^2 where 1 < t < 2.  Here is how
we compute the path integral:

First, we define our function:

(%i2) f(x,y):=x^2;
\[\tag{%o2} \operatorname{f}\left( x,y\right) :={{x}^{2}}\]

Now, we define the curve *as a vector expression* (not as a function):

(%i3) [x,y]:[sqrt(t),t^2];
\[\tag{%o3} [\sqrt{t},{{t}^{2}}]\]

What this has done is automatically restricted f(x,y) to the curve!  Look:

(%i4) f(x,y);
\[\tag{%o4} t\]

Now, the line integral of a scalar function requires the magnitude of the tangent vector so let's build the tangent vector:

(%i5) v:diff([x,y],t);
\[\tag{v}[\frac{1}{2 \sqrt{t}},2 t]\]

Now the integral:

(%i6) integrate(f(x,ymag(v),t,1,2);
\[\tag{%o6} \frac{\log{\left( \frac{\sqrt{2}\, \sqrt{129}+16}{4}\right) }}{48}-\frac{\log{\left( -\frac{\sqrt{2}\, \sqrt{129}-16}{4}\right) }}{48}-\frac{\log{\left( \sqrt{17}+4\right) }}{48}+\frac{\log{\left( 4-\sqrt{17}\right) }}{48}+\frac{\sqrt{2}\, \sqrt{129}}{3}-\frac{\sqrt{17}}{6}\]

To see what it is we just integrated we have:

(%i7) 'integrate(f(x,ymag(v),t,1,2);
\[\tag{%o7} \int_{1}^{2}{\left. t\, \sqrt{4 {{t}^{2}}+\frac{1}{4 t}}dt\right.}\]

Which is most definitely the result we were looking for.  To get a numerical result, we use a numerical integral:

(%i8) quad_qags(f(x,ymag(v),t,1,2)[1];
\[\tag{%o8} 4.709708413505119\]

 2 Streamlined Examples

 2.1 A Curve Example in 2D

Let's find the integral of f(x,y)=2+x^2y where the curve is the upper half of the unit circle.

(%i11) f(x,y):=2+x^2·y;
[x,y]:[cos(t),sin(t)];
v:diff([x,y],t);
\[\tag{%o9} \operatorname{f}\left( x,y\right) :=2+{{x}^{2}} y\] \[\tag{%o10} [\cos{(t)},\sin{(t)}]\] \[\tag{v}[-\sin{(t)},\cos{(t)}]\]
(%i12) integrate(f(x,ymag(v),t,0,%pi);
\[\tag{%o12} 2 \ensuremath{\pi} +\frac{2}{3}\]

 2.2 A Curve Example in 3D

Let's find the integral of f(x,y,z)=ysin(z) where the curve is the helix [cos(t),sin(t),t] and 0 < t <2%pi.

(%i16) f(x,y,z):=y·sin(z);
[x,y,z]:[cos(t),sin(t),t];
v:diff([x,y,z],t);
integrate(f(x,y,zmag(v),t,0,2·%pi);
\[\tag{%o13} \operatorname{f}\left( x,y,z\right) :=y \sin{(z)}\] \[\tag{%o14} [\cos{(t)},\sin{(t)},t]\] \[\tag{v}[-\sin{(t)},\cos{(t)},1]\mbox{atanh: argument 1 isn't in the domain of atanh.}\mbox{ -- an error. To debug this try: debugmode(true);}\]

Hmmm... that's interesting... let's take a look at the integrand to see what's up:

(%i17) f(x,y,zmag(v);
\[\tag{%o17} {{\sin{(t)}}^{2}}\, \sqrt{{{\sin{(t)}}^{2}}+{{\cos{(t)}}^{2}}+1}\]

This really shouldn't be an issue, since the above is just sqrt(2)*sin(t)^2.  What we are seeing here is the symbolic integrator
being thrown off by an unsimplified integrand.  Let's just simplify it with trigsimp() to see if that helps:

(%i18) integrate(f(x,y,ztrigsimp(mag(v)),t,0,2·%pi);
\[\tag{%o18} \sqrt{2} \ensuremath{\pi} \]

Aha!  That's better!  In general it is a good idea to trigsimp() or ratsimp() your integrands to help the symbolic integrator
as much as possible.  We also note that the numerical integrator has no problems whatsoever with the above:

(%i19) quad_qags(f(x,y,zmag(v),t,0,2·%pi)[1];
\[\tag{%o19} 4.442882938158366\]
(%i20) float(sqrt(2%pi);
\[\tag{%o20} 4.442882938158366\]

Nice!

 2.3 Last 3D Example

Let's compute the exact value of f(x,y,z)=x^3y^2z over the curve [exp(-t)cos(4t),exp(-t)sin(4t),exp(-t)] where 0 < t < 2%pi:

(%i23) f(x,y,z):=x^3·y^2·z;
[x,y,z]:[exp(tcos(4·t),exp(tsin(4·t),exp(t)];
v:diff([x,y,z],t);
\[\tag{%o21} \operatorname{f}\left( x,y,z\right) :={{x}^{3}}\, {{y}^{2}} z\] \[\tag{%o22} [{{\% e}^{-t}} \cos{\left( 4 t\right) },{{\% e}^{-t}} \sin{\left( 4 t\right) },{{\% e}^{-t}}]\] \[\tag{v}[-4 {{\% e}^{-t}} \sin{\left( 4 t\right) }-{{\% e}^{-t}} \cos{\left( 4 t\right) },4 {{\% e}^{-t}} \cos{\left( 4 t\right) }-{{\% e}^{-t}} \sin{\left( 4 t\right) },-{{\% e}^{-t}}]\]
(%i24) integrate(f(x,y,ztrigsimp(mag(v)),t,0,2·%pi);
\[\tag{%o24} 3 \sqrt{2}\, \left( \frac{57568}{5632705}-\frac{57568 {{\% e}^{-14 \ensuremath{\pi} }}}{5632705}\right) \]

We note that in this case, trigsimp() was unnecessary since:

(%i25) integrate(f(x,y,zmag(v),t,0,2·%pi);
\[\tag{%o25} \frac{5397 {{2}^{\frac{11}{2}}}}{5632705}-\frac{5397 {{2}^{\frac{11}{2}}}\, {{\% e}^{-14 \ensuremath{\pi} }}}{5632705}\]

But since we didn't know that ahead of time, it didn't hurt to call it.  Finally, we note that this value is about:

(%i26) quad_qags(f(x,y,zmag(v),t,0,2·%pi)[1];
\[\tag{%o26} 0.04336110964023232\]

 3 Path Integrals

Computing path integrals works much in the same way that line integrals do with two major exceptions:

1.  We define a vector field instead of a scalar function for the integrand

2.  We dot the tangent vector with the field rather than find the magnitude.

Let's find the line integral of F = x i +yj + zk over one turn of the helix [cos(t),sin(t),t]

(%i30) F(x,y,z):=[x,y,z];
[x,y,z]:[cos(t),sin(t),t];
v:diff([x,y,z],t);
integrate(F(x,y,z).v,t,0,2·%pi);
\[\tag{%o27} \operatorname{F}\left( x,y,z\right) :=[x,y,z]\] \[\tag{%o28} [\cos{(t)},\sin{(t)},t]\] \[\tag{v}[-\sin{(t)},\cos{(t)},1]\] \[\tag{%o30} 2 {{\ensuremath{\pi} }^{2}}\]

Note that the above could be compressed into simply:

(%i33) F:[x,y,z]$
[x,y,z]:[cos(t),sin(t),t]$
integrate(F.diff([x,y,z],t),t,0,2·%pi);
\[\tag{%o33} 2 {{\ensuremath{\pi} }^{2}}\]

Let's do a few more examples:

 3.1 Work Example

Find the approximate work done (in Joules) by the field F = [xy, sin(y)] pushing a particle over the curve [exp(t),exp(-t^2)] for 1 < t < 2.

(%i39) F:[x·y,sin(y)]$
[x,y]:[exp(t),exp(t^2)]$
quad_qags(F.diff([x,y],t),t,1,2)[1];
\[\tag{%o39} 1.963338271501951\]

The work is about 1.9633 J.

 4 Caution!

Note that in our approach to the above examples, we have been consistently binding x, y, and z to various expressions in terms of t.  This means that everytime after that you type x, y or z, you will be getting (for instance)

(%i42) x;y;z;
\[\tag{%o40} {{\% e}^{t}}\] \[\tag{%o41} {{\% e}^{-{{t}^{2}}}}\] \[\tag{%o42} t\]

To be safe, once you have completed your integrals, you should kill off at least x,y,z:

(%i43) kill(x,y,z);
\[\tag{%o43} \mathit{done}\]
(%i46) x; y; z;
\[\tag{%o44} x\] \[\tag{%o45} y\] \[\tag{%o46} z\]
Created with wxMaxima.