Lab 6A - Surface Integrals of Scalar Functions
Math 2374 - University of Minnesota
questions to:


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^1xx, 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 2B.  You might find it useful to open Lab 2B 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}]


(x^2 + y^2 + z^2)^(1/2)

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.


Just for your reference, we'll repeat the definition of a surface integral of a scalar function.

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:

∫∫_Mg σ = ∫∫_Rg (f (s, t))  ∂f/s  ∂f/∂t ds dt


(This is based on similar examples in most textbooks.  Here we'll concentrate on the concepts and let Mathematica do all the hard work.)

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 2B 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 open 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]} ; ParametricPlot3D[f[theta, phi], {theta, 0, 2Pi}, {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]} ; ParametricPlot3D[graph[t, p], {p, 0, Pi/2}, {t, 0, 2Pi}, 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]


{-Sin[p] Sin[t], Cos[t] Sin[p], 0}


{Cos[p] Cos[t], Cos[p] Sin[t], -Sin[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]


√ (Cos[t]^2 Sin[p]^4 + Sin[p]^4 Sin[t]^2 + (Cos[p] Cos[t]^2 Sin[p] + Cos[p] Sin[p] Sin[t]^2)^2)

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]]


Cos[p] (Cos[t]^2 Sin[p]^2 + Sin[p]^2 Sin[t]^2)

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, 2Pi}]


Cos[p] (Sin[p]^2)^(3/2)



So if g represents the density of the material of the hemisphere, the total mass of the hemisphere is FormBox[RowBox[{π/2, ≈, 1.571}], TraditionalForm].

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.  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, 2Pi}] mass2 = Integrate[integrand, {p, Pi/6, 2Pi/6}, {t, 0, 2Pi}] mass3 = Integrate[integrand, {p, 2Pi/6, 3Pi/6}, {t, 0, 2Pi}]






(7 π)/32

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, 2Pi}] area2 = Integrate[Norm[Cross ... Pi/6, 2Pi/6}, {t, 0, 2Pi}] area3 = Integrate[Norm[Cross[dp, dt]], {p, 2Pi/6, 3Pi/6}, {t, 0, 2Pi}]


-(-2 + 3^(1/2)) π


(-1 + 3^(1/2)) π




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.

In the homework you may have been asked 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 mathematica.  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.


Show[Graphics3D[Torus[3, 1]]]




In case you didn't manage to do the homework problem in question, here's the parametrization for a certain torus.  If you graph this parametrization with both θ and φ going from 0 to 2π, you'll see the whole torus.  (Try it if you'd like to.)  Note that I'm typing "t" and "p" instead of "theta" and "phi," or "θ" and "φ."


f[t_, p_] = {(Sin[t] + 3) Sin[p], (Sin[t] + 3) Cos[p], Cos[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≤φ≤2π and -π/2≤θ≤π/2.


ParametricPlot3D[f[t, p], {t, -Pi/2, Pi/2}, {p, 0, 2Pi}, PlotPoints {15, 30}] ;



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




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


ParametricPlot3D[f[t, p], {t, -Pi/2, Pi/2}, {p, 0, 2Pi}, PlotPoints {15, 30}] ;


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


RowBox[{RowBox[{g[t_, p_], =, RowBox[{{, RowBox[{(Sin[t] + 3) Sin[p], ,, (Sin[t] + 3) Cos[p],  ... lot3D[g[t, p], {t, -Pi/2, Pi/2}, {p, 0, 2Pi}, PlotPoints {15, 30}, 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.


(* density function *)g[x_, y_, z_] = z + 1 ; (*  parametriz ... 1;ans = Integrate[integrand, {t, -Pi/2, Pi/2}, {p, 0, 2Pi}] ; Simplify[ans] N[ans]


6 π (2 + π)



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!)


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[2Pi t], t Sin[2Pi t], s * (4 - t)} <br /> 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[2Pi t], t Sin[2Pi t], s * ( 2 + Sin[7Pi t])} <br /> 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[3t]/4)} <br /> ParametricPlot3DLive[f[p, t], {p, Pi/4, 3Pi/4}, {t, 0, 2Pi}]

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.


Created by Mathematica  (November 6, 2004)