Application Center - Maplesoft

App Preview:

Calculus II: Lesson 6: Applications of Integration 4: Arc Length of Graphs

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

Learn about Maple
Download Application



Calculus II

Lesson 6: Applications of Integration 4: Arc Length of Graphs

Arc length of graphs

Suppose you are given the graph of a function f on an interval [a, b] . How would you find the length of the graph? If f were a linear function, the length of the graph would just be the distance between its endpoints, and you could find its length with the distance formula.

> restart; with(plots):

Warning, the name changecoords has been redefined

> f := x-> 2*x + 3 ;

f := proc (x) options operator, arrow; 2*x+3 end pr...

> plot(f, -1..2);

[Maple Plot]

> l := sqrt((2 - (-1))^2 + (f(2) - f(-1))^2);

l := 3*sqrt(5)

Check How do we proceed if f is not linear? Let's take a specific example:

> f := x-> 4*x^2 - x^3 ;

f := proc (x) options operator, arrow; 4*x^2-x^3 en...

> plot(f, -1..4);

[Maple Plot]

Let's try to find the arclength of f over the interval [0, 2] . The crucial observation is that although f is obviously not linear, it will be approximately linear on any sufficiently small subinterval. (Why?) This suggests that we divide the interval [0, 2] into a sufficient number of equal subintervals, and approximate f by a suitable linear function on each subinterval. The following procedure does this in general: it takes a function, an interval [a, b] , and the number of subintervals to use, and returns a function which is a piecewise-linear approximation to f . (You don't need to understand the syntax of the procedure, although most of it should be familiar to you: the graphs we are going to plot should make clear what it is doing.)

> pl := proc(f,a,b,n)

> local u,v,k;

> k := 1 + floor(n*(x-a)/(b-a));

> u := a + (k-1)*(b-a)/n;

> v := a + k*(b-a)/n;

> unapply(f(u) + (f(v) - f(u))/(v-u)*(x-u), x);

> end:

> plot([f,pl(f,-1,4,4)], -1..4, thickness=2, color=[red, blue]);

[Maple Plot]

> display( [seq( plot([f, pl(f,-1, 4 ,i)], -1..4, thickness=2, color=[red, blue]), i=1..20) ], insequence=true);

[Maple Plot]

Question 1

Plot the function below, and some piecewise-linear approximations to it, over the interval [0, Pi] .


> g := x-> cos(x)^2 ;

g := proc (x) options operator, arrow; cos(x)^2 end...

> plot([g,pl(g,0,Pi,5)], 0..Pi);

[Maple Plot]

> display( [seq( plot([g, pl(g, 0, Pi ,i)], 0..Pi, thickness=2, color=[red, blue]), i=1..20) ], insequence=true);

[Maple Plot]


Now that we have our piecewise-linear approximation, we can approximate the length of the original

graph by adding up the lengths of the approximating line segments. The line segment over the k -th subinterval joins the points ( x_(k-1), f(x_(k-1)) ) and ( x_k, f(x_k) ), where x_k = a+k*(b-a)/n .

Computing the length of each line segment, then adding, gives the approximation


to the length of the graph.

Question 2

Translate this formula into Maple syntax by writing a function approxlen which takes a function f , an interval [a, b] and a number of subintervals n , and returns the length of the n -subinterval piecewise-linear approximation to the length of the graph of f . Your function should look something like proc(f,a,b,n) ... end: . Test your approxlen function using the functions f and g defined earlier. If you have time, try some other functions as well.

Solution. The following procedure does the job. We have used a local variable inside the procedure to minimise typing: l is the length of one subinterval.

> approxlen := proc(f,a,b,n)
local l;

> l := (b-a)/n;

> sum(sqrt(l^2 + (f(a+k*l) - f(a+(k-1)*l))^2), k=1..n);

> end:

The function approxlen gives the exact length of the piecewise-linear graph. As you can see from the first piece of output below, this is not necessarily very useful. To see what is really happening, we use evalf .

> approxlen(f,0,2,5);


> evalf(approxlen(f,0,2,5));


> evalf(approxlen(f,0,2,10));


> evalf(approxlen(f,0,2,100));


> evalf(approxlen(f,0,2,1000));


Notice how the length of the piecewise-linear approximations seem to converge (to 3.26...) as we use more and more subintervals. A similar thing happens if we approximate the function g :

> evalf(approxlen(g,0,Pi,5));


> evalf(approxlen(g,0,Pi,10));


> evalf(approxlen(g,0,Pi,100));


> evalf(approxlen(g,0,Pi,1000));


At this point, you should feel reasonably confident that we have found the lengths of the graphs of f and g to within 2 decimal places, and possibly even 3. Presumably, we could get better approximations--in fact as good as we like--by taking more subintervals. Notice that we have not yet evaluated any integrals!

The final step in the integration procedure is to take the limit of the approximations as proc (n) options operator, arrow; infinity end proc... by recognising that the approximating sum is a Riemann sum for some interval. There is an extra difficulty in this case, which will be explained in class, but the final result is as expected: the exact length of the graph is a limit of Riemann sums, and is therefore given by an integral; in fact, the integral

int(sqrt(1+D(f)(x)^2),x = a .. b) .

(Remember that D(f) is Maple 's notation for the derivative of f .)

Question 4

Use this integral formula to compute the arclengths of the functions f and g defined earlier over the intervals [0, 2] and [0, Pi] respectively. In each case, compare with the piecewise-linear approximations to the lengths, and say how many subintervals are necessary for the error in the approximation to be no greater than 1%.

Solution. You can just evaluate the formula twice: once for f and once for g . Since the exact values is not very illuminating, we use evalf . (The first evaluation can take Maple a long time. As explained in the solution to Question 5, you can speed up the calculation by replacing the int command by the unevaluated version Int .)

> flength := evalf(Int(sqrt(1 + D(f)(x)^2), x=0..2));

flength := 3.264359655

> glength := evalf(Int(sqrt(1 + D(g)(x)^2), x=0..Pi));

glength := 3.820197789

To be within 1% of the length of the graph of f we must be in the interval

> [flength - 0.01*flength, flength + 0.01*flength];

[3.231716058, 3.297003252]

Comparison with the answers to Question 3 shows that 10 subintervals will be sufficient. (5 will not; you can find the exact number necessary if you wish.)

To be within 1% of the arclength of
g we should be in the interval

> [glength - 0.01*glength, glength + 0.01*glength];

[3.781995811, 3.858399767]

Once again, 10 subintervals (but not 5) will suffice.


Question 5 (optional)

Write a Maple function arclength which takes a function f and an interval [a, b] , and computes the (exact) length of the graph of f over [a, b] . Your function should look like proc(f,a,b) ... end: .

Solution. The simplest solution is the following:

> arclength1 := proc(f,a,b) Int(sqrt(1 + D(f)(x)^2), x=a..b) end:

Unfortunately, this can be rather slow, as in fact it is for our test function f :

> evalf(arclength1(f,0,2));


The reason is that since arclength contains the command int , Maple tries to evaluate the integral exactly before computing it as a decimal. This can take it a long time, and in fact can even cause it to freeze completely if it encounters an integral that it cannot evaluate. The (non-obvious) solution is to replace the int command with the unevaluated version Int . In this way, Maple looks for the decimal approximation first.

> arclength := proc(f,a,b) Int(sqrt(1 + D(f)(x)^2), x=a..b) end:

> evalf(arclength(f,0,2));


> evalf(arclength(g,0,Pi));