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 on an interval . How would you find the length of the graph? If 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 ;
> plot(f, -1..2);
> l := sqrt((2 - (-1))^2 + (f(2) - f(-1))^2);
Check How do we proceed if is not linear? Let's take a specific example:
> f := x-> 4*x^2 - x^3 ;
> plot(f, -1..4);
Let's try to find the arclength of over the interval . The crucial observation is that although is obviously not linear, it will be approximately linear on any sufficiently small subinterval. (Why?) This suggests that we divide the interval into a sufficient number of equal subintervals, and approximate by a suitable linear function on each subinterval. The following procedure does this in general: it takes a function, an interval , and the number of subintervals to use, and returns a function which is a piecewise-linear approximation to . (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]);
> display( [seq( plot([f, pl(f,-1, 4 ,i)], -1..4, thickness=2, color=[red, blue]), i=1..20) ], insequence=true);
Question 1
Plot the function below, and some piecewise-linear approximations to it, over the interval .
Solution.
> g := x-> cos(x)^2 ;
> plot([g,pl(g,0,Pi,5)], 0..Pi);
> display( [seq( plot([g, pl(g, 0, Pi ,i)], 0..Pi, thickness=2, color=[red, blue]), i=1..20) ], insequence=true);
>
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 -th subinterval joins the points ( ) and ( ), where .
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 , an interval and a number of subintervals , and returns the length of the -subinterval piecewise-linear approximation to the length of the graph of . Your function should look something like proc(f,a,b,n) ... end: . Test your approxlen function using the functions and 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: 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);
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 :
> 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 and 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 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
.
(Remember that is Maple 's notation for the derivative of .)
Question 4
Use this integral formula to compute the arclengths of the functions and defined earlier over the intervals and 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 and once for . 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));
> glength := evalf(Int(sqrt(1 + D(g)(x)^2), x=0..Pi));
To be within 1% of the length of the graph of we must be in the interval
> [flength - 0.01*flength, flength + 0.01*flength];
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 we should be in the interval
> [glength - 0.01*glength, glength + 0.01*glength];
Once again, 10 subintervals (but not 5) will suffice.
Question 5 (optional)
Write a Maple function arclength which takes a function and an interval , and computes the (exact) length of the graph of over . 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 :
> 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));