Lab 6A - Surface Integrals of Scalar Functions
Math 2374 - University of Minnesota
http://www.math.umn.edu/math2374
 questions to: rogness@math.umn.edu

Introduction

All semester long we've been taking the concepts you learned during the first year of calculus and generalizing them to higher dimensions.  For example,

◼ Instead of one derivative, now we have many different partial derivatives, one for each variable in the function.  (We also have a "total derivative," or "derivative matrix," which is a matrix made up of all the partial derivatives.)

◼ A single definite integral, such as (∫_0^1) x dx, could be thought of as an integral along the line segment on the x-axis where x ranges from 0 to 1.  We've generalized this idea to come up with line or path integrals, where we integrate over a curve in space instead of a line segment on the x-axis.

◼ We also have iterated integrals, which allow us to compute double and triple integrals.  Double integrals let us integrate a function over a region R in the xy-plane.

Over the next two weeks in lab, we're going to generalize this last idea.  Instead of integrating over a region R in the xy-plane, we're going to integrate over a two-dimensional region which is sitting in space, i.e. a surface.  This week we'll work with integrals of scalar functions on a surface; next week we'll integrate vector fields on a surface.

The concepts in this lab can be difficult to understand, so it's very important that you read through this whole lab; we'll try to give you lots of hints along the way, but they won't be very helpful hints if you miss them!  Half of the work in any of these problems is finding a parametrization for a surface, and many people have trouble with this part.  We've tried to make it easier on you by getting you started on parametrizing surfaces way back in Lab 4B.  You might find it useful to open Lab 4B in another window so you can refer back to it.

One reminder before we move on.  Many of the formulas involve the length (or norm) of a vector, i.e. ||(Overscript[x, ⇀])||.  You might recall from an earlier lab that we can compute this in Mathematica using the Norm function.  Evaluate the next two cells before moving on and make sure the output is what you would expect.

Norm[{1, 2, 3}]

Norm[{x, y, z}]

Mathematica has a built-in function called Norm, but it assumes that it's working with complex numbers (things like a + b i), so it doesn't work quite right for us.  Instead Norm is redefined in math2374.nb like this:

Norm[v_] = Sqrt[v . v];

(Here v is a vector.)  Why is this the correct definition?  Talk to your TA if you're not sure.

We're also going to use the command Cross to find the cross product of two vectors.  If you aren't sure how to use this command, look it up in the help browser.

Definition

Just for your reference, we'll repeat the definition of a surface integral of a scalar function.  This is definition 2.1 on page 431 of your textbook.

Let g:\(U ⊂ ℝ\^3⟶ℝ\)be a continuous function, and let M be a smooth surface lying in U that is parametrized by f(s,t), where (s, 
            t) ϵR ⊂ (ℝ^2).  The surface integral of g over M is:

∫(∫_M) g dS=∫(∫_R)g(f(s, t))‖\(∂f\/∂s×∂f\/∂t\)‖ds dt=∫(∫_R)g(f(s, t))‖(Subscript[T, S])×(Subscript[T, T])‖ds dt

An Example

Surface integrals can be difficult at first, so as a first example we will walk through how to setup and solve a surface integral, leaving the hard parts to mathematica.

Evaluate the surface integral of g(x, y, z) = ((x^2) + (y^2)) z over the upper half of the sphere of radius 1 centered at the origin.

The first step in any surface integral is generally to find a parametrization for the surface.  In this case we need to parametrize the upper half of the unit sphere.  There are a few ways to do this, but because this is a sphere, it's probably best to use spherical coordinates.

Recall from Lab 4B that one of the best ways to parametrize a surface is often to describe it in cylindrical or spherical coordinates, and then convert the description back into rectangular coordinates.  (Remember, our final parametrization has to be in rectangular coordinates!)  In this particular case, the description of the upper half of the sphere is simply ρ=1, where 0≤θ≤2π and 0≤ϕ≤π/2.  (If this doesn't make sense, you should turn back to section 1.4 in your textbook and re-read the section on spherical coordinates.)

So ρ is constant, and the angles θ and ϕ will be our parameters.  Using the change of coordinate formulas, we get the following parametrization (with the same bounds on θ and ϕ as before):

f[theta_, phi_] = {Sin[phi] Cos[theta], Sin[phi] Sin[theta], 
          Cos[phi]};
ParametricPlot3DLive[
      f[theta, phi], {theta, 0, 2  Pi}, {phi, 0, Pi/2}]

Now we're asked to integrate the function g(x, y, z) = ((x^2) + (y^2)) z over the sphere.  Sometimes people have a hard time visualizing what this actually means.  Suppose our hemisphere is made up of a mixture of different kinds of metals, and different parts of the sphere have a different density, represented by the function g.  Here's a different graph of our surface, where the hemisphere is colored according to the function g; lighter shades indicate larger values of g, while dark areas on the sphere represent areas where the value of g is lower.

FYI: You do not have to understand the following commands; just evaluate them to see the picture!  If you'd rather have a plain old graph instead of an interactive picture, change ParametricPlot3DLive to ParametricPlot3D.  I used a Live command here because we're going to refer to the picture again in a few minutes, so you can keep it off to the side in the Live window.

g[t_, p_] = Cos[p] Sin[p]^2;
graph[t_, p_] = {Sin[p] Cos[t], Sin[p] Sin[t], Cos[p], 
          GrayLevel[g[t, p]/ .4]};
ParametricPlot3DLive[graph[t, p], {p, 0, Pi/2}, {t, 0, 2  Pi}, 
      Lighting -> False]

So, for example, if g represents the density of the material making up the hemisphere, the lighter areas are constructed of much denser material than the darker areas.  The integral of g over the surface will give us the total mass of the hemisphere.

The first step to compute the integral, as you can see by looking at the definition above or in your book, is to find the partial derivatives of our parametrization f(θ,ϕ).  To save some typing and reading time, let's simply write "t" and "p" instead of "theta" and "phi" for our variable names.

dt = D[f[t, p], t]
dp = D[f[t, p], p]

Now we have to cross the partials and find the length of the resulting cross product.  Remember that we've defined a function Norm to do this for us.

v = Cross[dp, dt];
Norm[v]

This looks truly horrendous, but if you use Simplify you'll see that it's actually much better.

The other piece of our integrand is g(f(θ,ϕ)).  Recall from Lab 4A that the correct way to do this in Mathematica is to use the Apply command.  If you don't remember this, go look at Lab 4A again.

g[x_, y_, z_] = (x^2 + y^2) z;
Apply[g,  f[t, p]]

Again, this can be simplified if you like.

Now that you've seen how we can compute each piece of the integrand separately, we can do it all at once.  (If we had simply used this command right away it probably would have confused everybody)

integrand = 
      Simplify[Apply[g, f[t, p]]*
          Norm[Cross[dp, dt]]]
Integrate[integrand, {p, 0, Pi/2}, {t, 0, 2  Pi}]

So if g represents the density of the material of the hemisphere, the total mass of the hemisphere is π/2 ≈ 1.571.

Careful: we're being a bit sloppy here.  If we were actually working with densities and mass, we really ought to include units!  In fact, it's even worse; we usually think of our surfaces as being two-dimensional, whereas you might only think a three-dimensional object could have any mass.  If you prefer, you could imagine the surface as a very, very thin piece of paper or rubber.

Here's an interesting little afterthought that the book doesn't mention.  If you look at the earlier picture which is shaded in black and white according to g, you can see that the larger values of g are concentrated in the middle of the hemisphere.  Close to the north pole, the shading is much darker, which means the values of g are much smaller.  If g is a density function, that means there's not much mass in this part of the hemisphere.  To verify this with integrals, you can evaluate the following commands.  These are the same integrals as before, with one difference; instead of doing the whole hemisphere at once, the first integral is restricted to the area near the north pole (ϕ goes to π/6 instead of π/2=3π/6), the second integral does the "middle" of the hemisphere (π/6≤ϕ≤2π/6), and the third does the section near the equator (2π/6≤ϕ≤3π/6).

mass1 = 
      Integrate[
        integrand, {p, 0, Pi/6}, {t, 0, 2  Pi}]
mass2 = 
      Integrate[
        integrand, {p, Pi/6, 2  Pi/6}, {t, 0, 
          2  Pi}]
mass3 = 
      Integrate[integrand, {p, 2  Pi/6, 3  Pi/6}, {t, 0, 2  Pi}]

You might remember that average density is equal to mass divided by surface area.  We can find surface area of these pieces by integrating the function 1 over the surface.  Remember that if we're integrating 1, then the integrand is actually 1 times the length of the normal vector:

area1 = 
      Integrate[
        Norm[Cross[dp, dt]], {p, 0, Pi/6}, {t, 0, 
          2  Pi}]
area2 = 
      Integrate[
        Norm[Cross[dp, dt]], {p, Pi/6, 2  Pi/6}, {t, 0, 
          2  Pi}]
area3 = 
      Integrate[
        Norm[Cross[dp, dt]], {p, 2  Pi/6, 3  Pi/6}, {t, 0, 
          2  Pi}]

avgdens1 = N[mass1/area1]
avgdens2 = N[mass2/area2]
avgdens3 = N[mass3/area3]

So you can see that the density really is concentrated in the middle of the sphere, with somewhat less along the equator, and significantly less near the north pole!

Donuts and Chocolate Frosting

Now we come to the important, real world application: measuring chocolate.

Pages 421-422 in your book describe how to parametrize a "torus," which is the mathematical term for the surface of a donut shape.  This is a very famous and widely used surface in mathematics.  Mathematica even includes commands for drawing tori (not toruses!).  Note that you don't have to understand these commands, but you can evaluate them if you'd like to see a picture.

Needs["Graphics`Shapes`"]
ShowLive[Graphics3D[Torus[3, 1]]]

Here's the parametrization for a certain torus, with a = 3 and b = 1 in the book's notation.  If you graph this parametrization with both s and t going from 0 to 2π, you'll see the whole torus.  (Try it if you'd like to.)

f[s_, t_] = {(Cos[t] + 3) Cos[s], (Cos[t] + 3) Sin[s], 
          Sin[t]};

Here's the setup for our example.  Suppose we bake a donut, and then we dip it upside down in a vat of dark chocolate, so we coat the upper half of the donut with gooey chocolate frosting.  The chocolate in the vat isn't perfectly mixed, so the denser chocolate is settling at the bottom of the vat.  What that means is that the chocolate which ends up on the top of the donut -- remember, it's dipped upside down -- is denser than the chocolate on the sides.  We want to know how much chocolate is actually there.  We're going to do that by estimating the density of the chocolate coating at each point on the top half of the donut, and then integrating the density function over this half.

The way we've chosen the parametrization, the chocolate is on the top half of the torus, which just happens to be precisely those points on or above the xy-plane, where z=0.  Evaluate the next two commands to see pictures of the surface we're going to integrate over.  We use the same parametrization, but now 0 ≤ s ≤ 2  π and 0 ≤ t ≤ π.

ParametricPlot3D[f[s, t], {s, 0, 2  Pi}, {t, 0, Pi}, 
        PlotPoints -> {30, 15}];

ParametricPlot3D[f[s, t], {s, 0, 2  Pi}, {t, 0, Pi}, 
      PlotPoints -> {30, 15}, ViewPoint -> {2, 2, -2}]

Alternatively, you could evaluate the next command to show the surface in a LiveGraphics3D window:

ParametricPlot3DLive[f[s, t], {s, 0, 2  Pi}, {t, 0, Pi}, 
        PlotPoints -> {30, 15}];

Suppose the density function is g(x, y, z) = (z + 1) grams/(cm^2).  A graph of the chocolate surface looks like this:

g[s_, t_] = {(Cos[t] + 3) Cos[s], (Cos[t] + 3) Sin[s], 
          Sin[t], GrayLevel[(1.25 - Sin[t])/
              1.25]};
ParametricPlot3D[g[s, t], {s, 0, 2  Pi}, {t, 0, Pi}, 
      PlotPoints -> {30, 15}, Lighting -> False]

(Again, you do not need to understand these commands; they're just here so that you can see a picture which illustrates our situation.)

Unlike in the previous example, the darker shades here represent the denser chocolate (because our chocolate is dark, after all).  Now that we've seen all of the pretty pictures, we're ready to calculate the mass of the chocolate by integrating g over the top half of the torus.  I'm not going to explain the commands much, so if you don't understand what's going on, scroll back up and look at the first example again.  I will make a few comments; they are in between the (* and *) symbols.

g[x_, y_, z_] = 
        z + 1 ;

  

  

    ds = D[f[s, t], s];

    dt = D[f[s, t], t];

  

    integrand = 
        Simplify[Apply[g, f[s, t]]]*Norm[Cross[ds, dt]];

    ans = 
        Integrate[integrand, {s, 0, 2  Pi}, {t, 0, Pi}];

    Simplify[ans]

    N[ans]

There are semicolons after most of these commands, so the only outputs are the final answer, in simplified form, and a numerical approximation.  If you'd like to see the partials, or the integrand, you can remove the appropriate semicolons and evaluate the cell again.

So with our given setup, there are almost 97 grams of chocolate on this surface.  (Sounds like a good donut!)

Exercises

Note: in the examples above, you were shown graphs which were colored according to the scalar function g(x,y,z), instead of Mathematica's normal internal coloring scheme.  You do not have to produce these kinds of graphs in your lab report!

Exercise 1

Find the surface area of the surface parametrized (and graphed) by the following commands.  (You will need to cut and paste before you can evaluate them.)

f[s_, t_] = {t Cos[2  Pi t],  t Sin[2  Pi t],  
          s *(4 - t)}
ParametricPlot3D[f[s, t], {s, 0, 1}, {t, 0, 4}, 
        PlotPoints -> {5, 200}]

Your answer should include a sketch of the surface, your exact answer -- which will be ugly -- and a numeric approximation, which you can find using the N command in Mathematica.  Alternatively, you could use the command NIntegrate to get your numeric approximation.  NIntegrate will not try to give you an exact answer, but will only give you the approximation.

Exercise 2

Find the surface area of the surface parametrized (and graphed) by the following commands.  (You will need to cut and paste before you can evaluate them.)

f[s_, t_] = {t Cos[2  Pi t],  t Sin[2  Pi t], 
          s*( 2 + Sin[7  Pi t])}
ParametricPlot3D[f[s, t], {s, 0, 1}, {t, 0, 4}, 
        PlotPoints -> {5, 200}]

Your answer should include a sketch of the surface, and a numeric approximation to the final answer.  You'll have to use NIntegrate instead of Integrate (see exercise 1).  Integrate will think for a long, long time and probably not give you an answer.

Exercise 3

Evaluate the surface integral of the function g(x, y, z) = x over the surface which is the graph of z = Sin[x] Cos[y], where 0≤x≤2π and -π≤y≤π.  Note that you will have to use NIntegrate with this exercise; once again Integrate can't quite get the answer, although it gives it a good try.

Exercise 4

Evaluate the surface integral of the function g(x, y, z) = (x^2) + (y^2) over the following surface:

f[p_, t_] = {Sin[p] Cos[t], Sin[p] Sin[t], 
          Cos[p] (1 + Cos[3  t]/4)}
ParametricPlot3DLive[f[p, t], {p, Pi/4, 3  Pi/4}, {t, 0, 2  Pi}]

You should include a picture of the surface along with your work.  As with exercises 2 and 3, you'll have to use NIntegrate here.

Credits

This lab was written from scratch in February/March 2002.  Previously there was no lab which dealt with surface integrals of scalar functions.  I intetionally kept this lab short (only two exercises to hand in, generally) to provide some relief from earlier labs, which were much longer.  I made minor updates in April 2004 -- new exercises, a bit of LiveGraphics3D stuff, etc.

More updates made by Rob Edman in April 2005. Just updated to reflect the new book.

The First example was previously labeled "Example 5.6.2", and has been changed to "An Example". The problem is unchanged and was taken from Barr p.342

This lab is copyright 2002, 2004 by Jonathan Rogness (rogness@math.umn.edu) and is protected by the Creative Commons Attribution-NonCommercial-ShareAlike License.  You can find more information on this license at http://creativecommons.org/licenses/by-nc-sa/1.0/

Although it's not specifically required by the license, I'd appreciate it if you let me know if you use parts of our labs, just so I can keep track of it.  Please send me any questions or comments!