Untitled

895 days ago by pub

GOAL: Calculate the line integral (of function type) $\int_C f \, ds $ where $C$ is a curve.

We will solve the (relatively) simple problem: Calculate the length of the curve y=cos(x), $0 \le x \le \pi$.

Cool graphs with explanations are at the bottom!

Related Sage pages:    Next: Example 1     Back: Arc Length  



Formula Sheet  Arc Length is: $L=\int_C \, ds$   and  Line Integral of function f over C is: $I=\int_C \, f \, ds$.

How do we solve this?

1. Let $\vec s(t)= \lt x(t),y(t),z(t) \gt$, $t \in [t_1,t_2]$ be a vector-parameterization of the curve C.

2. Find the derivative vector:   $d\vec s(t)=\lt \dot{x}(t),\,\dot{y}(t),\, \dot{z}(t) \gt$.

3. The line element $ds$ is the magnitude (norm) of this vector:   $ds=\sqrt{{\dot{x}}^2 + {\dot{y}}^2 + {\dot{z}}^2} \, dt$. 

4. Substitute the components:   $\vec s =\lt x,\, y,\, z \gt$ into function $f(x,y,z)$ to get function $f(t)$.

5. Integrand is the (regular) product:   $f(t) \cdot \sqrt{{\dot{x}}^2 + {\dot{y}}^2 + {\dot{z}}^2}$. 

6. Integrate to get:   $\int_C \, f(x,y,z)\, ds= \int_{t_1}^{t_2}\, f(x(t),y(t),z(t)) \cdot \sqrt{{\dot{x}}^2 + {\dot{y}}^2 + {\dot{z}}^2} \, dt$

We can do steps 2-6 with SOLVER.

Preparation for SOLVER: We must parameterize the curve with 1 parameter and find the interval.

Work particular to the given problem: 

== Because we want length, our function of integration is $f(x,y,z)=1$

== We have an explicit function for the surface $y=\cos (t)$. So we just let $x=t$, $y=cos(t)$. Since we are in 2d (we have no z), we set $z=0$.

== $[t_1,t_2]$ is the projection of the curve onto the t-axis and since x=t, this means the x-axis and the x-interval is the t-interval, $t \in [0,\pi ] $.

==> $\vec s(t)= \,\left\{ \begin{array}{l}x = t \\y = \cos (t)\\z =0 \end{array} \right.\,\,\,\,\,t \in [0,\pi ] $

Here the parameterization and interval is direct. Often times we will be given a curve that is the intersection of 2 surfaces. Then, you have to do the parameterization by hand. There is no way around this! 


SOLVER: Our program follows the hand solution method. Everything in red requires something particular to your problem!

  1. Input from preparation for SOLVER
    • Parameterize C with s(t) and input as vector function. Requires parametrization - done above.
    • Find interval and input. Requires work - done above.
    • Input function f(x,y,z).
  2. Find the derivative vector $d \vec s(t)$ of $\vec s(t)$. 
  3. Find the magnitude (intensity) of this vector $\left\| {ds} \right\|$ .
  4. Substitute parameterization in f to get function of t.
  5. Find the integrand by multiplying f and $\left\| {ds} \right\|$ from step 3.
  6. Integrate.
var ('t'); var('x y z') 
       
\newcommand{\Bold}[1]{\mathbf{#1}}t
\newcommand{\Bold}[1]{\mathbf{#1}}\left(x, y, z\right)
                                
                            
\newcommand{\Bold}[1]{\mathbf{#1}}t
\newcommand{\Bold}[1]{\mathbf{#1}}\left(x, y, z\right)
                                

Step 1: We define $C$ as vector function $\vec s(t)$, input our interval on t and define $f(x,y,z)$. Changes with problem; you must input your parametrization in C as s(t), your interval for t and your function of f(x,y,z).

s=vector((t,cos(t),0)) t1=0; t2=pi f=1 
       

Step 2: The program finds the vector function with the derivatives: $d \vec s(t)=\lt {\dot{x}},\, {\dot{y}},\, {\dot{z}} \gt$

ds=diff(s,t) view(ds) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(1,\,-\sin\left(t\right),\,0\right)
                                
                            
\newcommand{\Bold}[1]{\mathbf{#1}}\left(1,\,-\sin\left(t\right),\,0\right)
                                

Step 3: The program calculates the magnitude of the vector function Cprime: $\left\| {ds} \right\|$ = norm of ds = $nds= \sqrt{{\dot{x}}^2 + {\dot{y}}^2 + {\dot{z}}^2}$

nds=norm(ds) view(nds) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -\sin\left(t\right) \right|}^{2} + 1}
                                
                            
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -\sin\left(t\right) \right|}^{2} + 1}
                                

Step 4: The program defines a standard sage function for "change of variables" for a 1-variable parametrization (surface).

The program changes the variables of $f$ from a function of (x,y,z) to a function of t using s(t).

def changevar(h, eqn, newvar1): return h.substitute(eqn) 
       
f=changevar(f,x==s[0],t) f=changevar(f,y==s[1],t) f=changevar(f,z==s[2],t) view(f) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}1
                                
                            
\newcommand{\Bold}[1]{\mathbf{#1}}1
                                

Step 5: Then program finds the product of f and ds (the magnitude from step 3).

integrand=nds*f view(integrand) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -\sin\left(t\right) \right|}^{2} + 1}
                                
                            
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -\sin\left(t\right) \right|}^{2} + 1}
                                

Step 6: The program computes the integral. 

result=integral(integrand,(t,t1,t2)) view(result) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\int_{0}^{\pi} \sqrt{{\left| \sin\left(t\right) \right|}^{2} + 1}\,{d t}
                                
                            
\newcommand{\Bold}[1]{\mathbf{#1}}\int_{0}^{\pi} \sqrt{{\left| \sin\left(t\right) \right|}^{2} + 1}\,{d t}
                                
n(result) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}3.82019778903
                                
                            
\newcommand{\Bold}[1]{\mathbf{#1}}3.82019778903
                                


Answer: The length of the curve $y=\cos{(x)}$, $x \in [0, \pi ]$ is:  ≈ 3.82  

Notice that this is a non-elementary integral (i.e. you cannot integrate by hand), so there is no "exact" result. Only the numeric result.


We graph the curve in 3d (since most of our curves will be 3d). Our job was to find the length of this curve.

C=parametric_plot(s,(t,t1,t2),color='orange',thickness=8, opacity=.7) #Let's add a reference var ('x y z') xmin=0; xmax=pi+1; ymin=-2; ymax=2; zmin=-1; zmax=1 px0y= implicit_plot3d(z==0,(x,xmin,xmax),(y,ymin,ymax),(z,zmin,zmax), color='grey', opacity=0.3) Ax=line3d(([xmin,0,0],[xmax,0,0]), thickness=2, color='red') Ay=line3d(([0,ymin,0],[0,ymax,0]), thickness=2, color='blue') Az=line3d(([0,0,zmin],[0,0,zmax]), thickness=2, color='green') show(C+px0y+Ax+Ay+Az, aspect_ratio=[1,1,1]) 
       

For fun, we draw points on the curve that are evenly spaced with respect to t.

Notice that they do NOT appear to be evenly spaced on the cosine curve itself. This is because $ds=\sqrt{\sin^2t+1} \, dt$

steps=20 Cpoints=sum([point3d(s(t=a), color=hue((a+8)/8), size=10) for a in [t1..t2,step=(t2-t1)/steps]]) show(Cpoints+C+px0y+Ax+Ay+Az, aspect_ratio=[1,1,1]) 
       

We graph the integral. The value of the line integral is the "area" captured by the vertical lines (divided by the vector scale).

Here the vector scale = vs = 1 and the area is the length of the curve. Since f=1, height of the lines is the "amount" of curve per unit t.

Where the curve is flat (at t=0 and at t=π), the "amount" is 1. This is the smallest value. Where the curve is steepest (at $t= {\pi \over 2}$), more curve is being "stuffed" in and the "amount" is $\sqrt{2} \approx 1.4$.

Notice that their height averages about 1.15. Multiplied by the length $\pi$ of the interval give us $\approx 3.82$.

p = plot(0,(t,t1,t2),color='red',thickness=3) steps=20; vector_scale=1 vf=sum([line(((a,0),(a,integrand(t=a)*vector_scale)), color=hue((a+8)/16)) for a in [t1..t2,step=(t2-t1)/steps] ]) show(p+vf,figsize=4,aspect_ratio=1)