25.4 Numerical Evaluation of Line Integrals

Suppose we confront a line integral, which is an integral along a path in some Euclidean space, of a vector field vds

We can set up a spreadsheet to evaluate such an integral with very little difficulty.

In this section we describe how this can be done, and attempt to goad you into doing one yourself on a spreadsheet.

By the way, once you have such a thing, you can modify the path or the integrand or your grid size with a tiny amount of effort, and so can use your product to evaluate any line integral you ever encounter.

A line integral is more complicated than an ordinary integral primarily in that you have to deal with a path as well as an integrand, while for an ordinary integrand the path is an interval of the real line which is completely characterized by two numbers, its endpoints, and you need only deal with the integrand.

What we do depends on how the path C on which the integral is to be evaluated is defined.

The easiest case, which we address here, occurs when we are given C as a parametrized curve.

This means that we have a parameter, let us call it t, and have formulae for each coordinate, x, y, z,..., as functions of t, and an interval of t values defines the curve.

Our plan is to break up the t interval into many small pieces, and at the boundaries of these pieces calculate x(t), y(t), z(t), and vx(x(t), y(t), ...), vy(x(t), y(t), ...), ...

In words, we will devote a column to the calculation of each of x, y and z (in three dimensions); and to each component of the vector field v, evaluated at (x(t), y(t), z(t)). Then we use a column to describe the contribution to the integral from one subinterval, say between t and t + d.

And what do we use to estimate that contribution?

t is the change in x(t) over that interval multiplied by the average value of vx over the endpoints of the interval plus the same thing in y and in z. We write down only the x contribution here, which is

In the last column we add up these contributions over the various intervals, and that is our integral. This is the trapezoid rule for line integrals.

Once this is done, how do we change the path? Alter the x(t), y(t) and z(t) columns to use different functions of t.

How do we change the integrand, v? Change its columns.

How do we change the interval size parameter d? Just change it.

Exactly how do we do this?

I like to leave the top five or so rows for notes and data entry.

In B2 I would put the starting t value and in B3 the value for d.

In the top row I would give a verbal description of the curve and vector field.

So I would start the computation in row 6.

Here is what I would put in the t column, column A




And I would copy A8 down the sheet into A9-A1005. (or further if you like)

In the x, y and z columns put

B6=x(A6) (you must put in what this function is of course)

C6= y(A6)


And copy these down to B7-B1005, etc.

In the v columns put the values for the components of v




And copy these down.

Next set


And copy this into the I6 and J6 places, and down the sheet.





And copy these down, and you are done.

If the final t value occurs in Ak, then the integrand answer will be in Lk.

You can adjust d and can extrapolate exactly as for ordinary integrals.

The method used here is the path integral version of the trapezoid rule.

With a little guile you can extrapolate this to get a path integral version of Simpson's rule, and extrapolate that as well.

You can check on accuracy by doing the integral for one d value and for 2d and 4d as well (make sure you adjust the endpoint suitably, to check on your accuracy).

Without extrapolation the differences in answers should go down by a factor of 4 when you decrease d by a factor of two; taking of the finer result less or the coarser one should improve the result to Simpson.

And so on.