Line Integral of Function - Example 1

80 days ago by lfahlberg

Let C be the curve defined parametrically with C= \vec s(t) =\lt 3 \cos (t),\, 3 \sin (t),\, 4t \gt, t \in [0,2\pi ].  

Problem 1. Find the length of the curve C.     YouTube Video

Problem 2. Find the line integral of the function f(x,y,z)=\frac{1}{x^2+y^2+z^2} over C.     YouTube Video

Other Sage pages for Line Integral of Function:    SOLVER   Example 2



Formula Sheet  Arc Length is: L=\int_C \, ds   and  Line Integral is: I=\int_C \, f \, ds.

Formula for 1: L=\int_C \, ds = \int_{t_1}^{t_2}\, \sqrt{{\dot{x}}^2 + {\dot{y}}^2 + {\dot{z}}^2} \, dt      That is, f=1.  See also: Arc Length of Curve in 3D

Formula for 2: I=\int_C \, \frac{ds}{x^2+y^2+z^2} = \int_{t_1}^{t_2}\, \frac{1}{ [x(t)]^2+[y(t)]^2+[z(t)]^2} \cdot \sqrt{{\dot{x}}^2 + {\dot{y}}^2 + {\dot{z}}^2} \, dt

Preparation for using the SOLVER. The curve C is already parameterized and we have the interval for t. Visualization below. Click and drag to see!

var ('t') s=vector((3*cos(t),3*sin(t),4*t)) t1=0; t2=2*pi C=parametric_plot(s,(t,t1,t2),color='orange',thickness=8, opacity=.7) #Let's add a reference var ('x y z') xmin=-3; xmax=3; ymin=-3; ymax=3; zmin=-1; zmax=29 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=[3,3,1]) 
       

This is called a helix. Click and drag the graph so that you see the projection onto x0y is a circle. This is because the coefficients of x(t) and y(t) are equal r=3. If they were different, the helix would be eliptical. The coefficient h=4 on z(t) determines the height (stretch) of the helix.


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

Notice that they appear to be evenly spaced on the helix itself. If so, then ds=constant ·dt

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

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)



SOLVER: Problem 1  Find the length of C.


Step 1: We define C as \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((3*cos(t),3*sin(t),4*t)) t1=0; t2=2*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(-3 \, \sin\left(t\right),\,3 \, \cos\left(t\right),\,4\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(-3 \, \sin\left(t\right),\,3 \, \cos\left(t\right),\,4\right)

Step 3: The program calculates the magnitude of the vector function ds(t):  \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| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}

Our problem - look carefully at this: nds=\sqrt{9 \sin^2(t)+9 \cos^2(t)+16}=\sqrt{9+16}=\sqrt{9+16}=5 is a CONSTANT as we predicted from the "evenly spaced" points on the helix.


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=f*nds view(integrand) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}

Step 6: The program computes the integral.

result=integral(integrand,(t,t1,t2)) view(result) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}10 \, \pi
\newcommand{\Bold}[1]{\mathbf{#1}}10 \, \pi
n(result) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}31.4159265358979
\newcommand{\Bold}[1]{\mathbf{#1}}31.4159265358979

Answer: The length of the curve C is: L=10 \pi ≈ 31.42  

Notice the height of the vertical lines is constant = 5. This is nds.

There are lots of fun things to think about here. How does the radius of the helix (r=3) and the height of the helix (h=4) affect the length of the helix? What if the helix was elliptical?


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

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

We saw above nds=5 and here below that the curve curves at a constant "rate" of 5. Multiplied by the length of the interval 2\pi, which is the length of the curve.

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) 
       
#Here is the plot as in Arc Length for Curves in 3D steps=20 stepsize=(t2-t1)/steps points=sum([point3d(s(t=j), color='purple', size=10) for j in [t1..t2-stepsize,step=stepsize]]) pieces=sum([line3d([(s(t=j)),(s(t=j)+ds(t=j)*stepsize)],thickness=4,color='purple') for j in [t1..t2-stepsize,step=stepsize]]) show(C+pieces+points, aspect_ratio=[3,3,1]) 
       



SOLVER: Problem 2   Find line integral of the function f(x,y,z)=\frac{1}{x^2+y^2+z^2} over C.

So that SAGE does not get confused we concat a "1" to every variable name (even the ones that don't change).


Step 1: We define C as 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).

s1=vector((3*cos(t),3*sin(t),4*t)) t1=0; t2=2*pi f1=1/(x^2+y^2+z^2) 
       

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

ds1=diff(s1,t) view(ds1) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(-3 \, \sin\left(t\right),\,3 \, \cos\left(t\right),\,4\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(-3 \, \sin\left(t\right),\,3 \, \cos\left(t\right),\,4\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}

nds1=norm(ds1) view(nds1) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}
\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{{\left| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}

As above - for this problem, nds=\sqrt{9 \sin^2(t)+9 \cos^2(t)+16}=\sqrt{9+16}=\sqrt{9+16}=5 is a CONSTANT.


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) 
       
f1=changevar(f1,x==s1[0],t) f1=changevar(f1,y==s1[1],t) f1=changevar(f1,z==s1[2],t) view(f1) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{16 \, t^{2} + 9 \, \sin\left(t\right)^{2} + 9 \, \cos\left(t\right)^{2}}
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{16 \, t^{2} + 9 \, \sin\left(t\right)^{2} + 9 \, \cos\left(t\right)^{2}}

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

integrand1=f1*nds1 view(integrand1) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\sqrt{{\left| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}}{16 \, t^{2} + 9 \, \sin\left(t\right)^{2} + 9 \, \cos\left(t\right)^{2}}
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\sqrt{{\left| -3 \, \sin\left(t\right) \right|}^{2} + {\left| 3 \, \cos\left(t\right) \right|}^{2} + 16}}{16 \, t^{2} + 9 \, \sin\left(t\right)^{2} + 9 \, \cos\left(t\right)^{2}}
result1=integral(integrand1,(t,t1,t2)) view(result1) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\int_{0}^{2 \, \pi} \frac{\sqrt{9 \, {\left| \sin\left(t\right) \right|}^{2} + 9 \, {\left| \cos\left(t\right) \right|}^{2} + 16}}{16 \, t^{2} + 9 \, \sin\left(t\right)^{2} + 9 \, \cos\left(t\right)^{2}}\,{d t}
\newcommand{\Bold}[1]{\mathbf{#1}}\int_{0}^{2 \, \pi} \frac{\sqrt{9 \, {\left| \sin\left(t\right) \right|}^{2} + 9 \, {\left| \cos\left(t\right) \right|}^{2} + 16}}{16 \, t^{2} + 9 \, \sin\left(t\right)^{2} + 9 \, \cos\left(t\right)^{2}}\,{d t}
n(result1) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}0.604996767986
\newcommand{\Bold}[1]{\mathbf{#1}}0.604996767986


Answer: I=\int_C \, \frac{ds}{x^2+y^2+z^2} \approx 0.60 

BTW: This is actually an elementary integral. I=\int_0^{2 \pi} \, \frac{dt}{16t^2+9}=\frac{5}{12} \cdot \arctan ({\frac{8 \pi}{3}})

Thinking: If the function f describes the "thickness" of the helix, how would you describe what is happening?


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. However f \ne 1.  We know that the curve curves at a constant "amount" of 5.

Divide the heights of the lines by this 5 and you get the value of f at that point on the curve.

p1 = plot(0,(t,t1,t2),color='red',thickness=3) steps1=20; vector_scale1=1 vf1=sum([line(((a,0),(a,integrand1(t=a)*vector_scale1)), color=hue((a+8)/16)) for a in [t1..t2,step=(t2-t1)/steps1] ]) show(p1+vf1,figsize=4,aspect_ratio=10) 
       

Think of f as giving the "thickness" of the curve (however f can be negative so this is not always a good analogy - see next example).  

Then the line integral \int_C \,f\,ds is the amount of 2d area of a piece of paper whose height is f and curled along curve. 

For fun, we draw a "sort of" representation of this by mapping f vertically. (Notice that we have exagerated this thickness x10 with the vector_scale.)

vector_scale2=10 steps2=50 v3d=sum([line(((3*cos(a),3*sin(a),4*a),(3*cos(a),3*sin(a),4*a+integrand1(t=a)*vector_scale2)), color=hue((a+8)/16), thickness=3) for a in [t1..t2,step=(t2-t1)/steps2] ]) show(v3d+C+px0y+Ax+Ay+Az, aspect_ratio=[3,3,1])