An Introduction to Mathematica (bonus problems for Math 23B)

by Ruben Agapito
Mathematics Department at UC Santa Cruz.

In this lab you will use Mathematica to get the answers to the bonus problems quickly. It is advisable to keep a pad and a pencil handy. All the problems require some set-up, and this is best done using paper and pencil. Remember the following rule of thumb for future sessions with Mathematica:

A few quiet thoughtful moments spent away from the computer can often eliminate hours of wasted effort at the keyboard.

1. Evaluation of Path and Line Integrals

Let's solve the following exercises:

1) Evaluate the path integral of f(x, y, z) = exp((Sqrt[z])) along the curve Γ: (Overscript[α,  ->]) (t) = (1, 2, (t^2)), where 0 ≤ t ≤ 1.

2) Evaluate

(∫_Γ) (x^2) dx - 
      xy dy + dz,

along the curve Γ given by the intersection of the surfaces z = (x^2) and y = 0, from the point (-1, 0, 1) to (1, 0, 1).

Solution for No. 1

Keep in mind that you should be able to do this first by hand. Mathematica gives you the answer but not the procedure to get it.

We start off by defining f, α and their composition f∘α. Pay attention to the use of curly braces in the definition of the arguments of f. This is necessary in order to get the right composition (but it is not recommended if we want to plot f).

f[{x_, y_, z_}] := Exp[(Sqrt[z])];
α[t_] := {1, 2, (t^2)};
f[α[t]]

We also need

Norm[α'[t]]

Then we compute the path integral (to get the integral symbol, go to File and select "BasicInput" from the Palettes menu):

(∫_0^1) 
          f[α[t]] Norm[α'[t]] \[DifferentialD]t

Solution for No. 2

We need to parametrize the curve Γ.

x = t;
y = 0;
z = (t^2);

where -1 ≤ t ≤ 1.

We now compute the differentials with respect to the parameter t (which can be done easily without using the computer):

d 
        x = dt, 
d y = 
      0 dt, 
d z = 
      2  t dt

Remark: The symbol d can be obtained by using the following sequence of keys: EscddEsc

Thus the integral is given by

(∫_(-1)^1)((t^2) - 0 + 
            2  t) \[DifferentialD]t

Remark: It is advisable to remove the variables you used in Mathematica before trying a new exercise. The way to do this is by using the command:

Remove["`*"]

(Bonus point) Problem 1:

Evaluate (∫_Γ)((x^3),x + y)· d(Overscript[s,  →]) , where Γ consists of the top half of the circle (x^2) + (y^2) = 1 from (1, 0) to (-1, 0) and the line segment from (-1, 0) to (-2, 3).

Solution:

We break up the curve into two paths:

\(TraditionalForm\`\(\(\(Γ\_1\) : \(α\& → \)(t) = \((cos\ t, \ sin\ t)\)\)\(,\)\)\) t ∈ [0, π]
\(TraditionalForm\`\(Γ\_2\) : \(β\& → \)(t) = \((\(-1\) - t, 3  t)\), \ t ∈ \([0, 1]\)\)

Now to perform the integration we do the following definitions

F[{x_, y_}] := {(x^3), x + y};
α[t_] := {Cos[t], Sin[t]};
β[t_] := {-1 - t, 3  t};

After making these definitions available in memory we compute the line integral

(∫_0^π) F[α[t]] . α'[
                t] \[DifferentialD]t+(∫_0^1) F[β[t]] . β'[
              t] \[DifferentialD]t

As an additional step we can plot the curve with labels attached:

plot1 = 
        ParametricPlot[α[t], {t, 0, π}, 
          PlotStyle -> Thickness[0.01]];
plot2 = 
        ParametricPlot[β[t], {t, 0, 1}, 
          PlotStyle -> Thickness[0.01]];
\(Show[{plot1, plot2}, AspectRatio -> Automatic, 
      Background -> GrayLevel[1], AxesLabel -> {"x", "y"}, 
      Epilog -> {Text[\*""\!\(Γ\_1\)"", {0.5, 
              1}, {\(-1\), 0}], 
          Text[\*""\!\(Γ\_2\)"", {\(-1.5\), 2}, {\(-1\), 
              0}]}]\)

(Bonus point) Problem 2:

Evaluate the line integral (∫_Γ)F ds where F(x, y) = (e^(x - 1)) + x y and Γ is given by (Overscript[α,  →]) (t)=(t^2)(Overscript[i, →])+(t^3)(Overscript[j, →]), 0 ≤ t ≤ 1.  (This line integral is not easy to integrate by hand and numerical integration is advisable. Use the Mathematica command "NIntegrate[f, {x, xmin, xmax}]").

Solution:

Remove["`*"]

F[{x_, y_}] := 
        Exp[x - 1] + x*y;
α[t_] := {(t^2), 
          (t^3)};
(∫_0^1) F[α[t]]*
          Norm[α'[t]] \[DifferentialD]t

% // N

2. Double Integrals in Mathematica

We have learned in class that we can use iterated integrals whenever the region of integration is a rectangle, and the order of integration can be easily interchanged.

Rectangular Regions

Example: Compute the integral (Underscript[(∫∫), D]) (e^(x + 
              y)) dx dy, where D is the region: 0 ≤ x ≤ 1, 0 ≤ y ≤ 1.

Solution: We simply translate the integral into a convenient form understood by Mathematica.

(∫_0^1)(∫_0^1) Exp[
            x + y] \[DifferentialD]x \[DifferentialD]y

General Regions

Suppose that f is a continuous function over a (y-simple) region D in the plane described by

a ≤ x ≤ b and g(x) ≤ 
        y ≤ h(x).

Then the integral of f over D is given by the iterated integral

\(TraditionalForm\`∫\_a\%b\(∫\_\(g(x)\)\%\(h(x)\)\(f(x, y)\) dy dx\)\).

On the other hand, if D is described by (a x-simple region)

g(y) ≤ x ≤ h(y) and c ≤ y ≤ d,

then the integral of f over D is given by

(∫_c^d)(∫_(g(y))^(h(y)))f(
            x, y) dx dy.

Remark: Notice that the limits of the outermost integral consist of numbers and not functions.

Let's study some examples (which you should try first using pencil and paper) and use Mathematica to solve them.

Example: Find the volume of the solid that lies under the surface z = x (y^2) and over the triangular region with vertices (0, 0), (1, 1), and (1, 2).

Solution: A picture of the solid is given below:

Inequalities that describe the region are 0 ≤ x ≤ 1 and x ≤ y ≤ 2  x. Consequently, we will integrate ﬁrst with respect to y and then x.

This computes the volume:

(∫_0^1)(∫_x^(2  x))x (y^2) \[DifferentialD]y \[DifferentialD]x

Example: Find the volume of the solid that lies under the surface z = (x^2) (y^2) and over the region described by 0 ≤ x ≤ sin y and 0 ≤ y ≤ π.

Solution: A graph of the solid is given below:

Because of how the region is described, we must integrate ﬁrst with respect to x and then y.

(∫_0^π)(∫_0^(Sin[y]))(x^2) (y^2) \[DifferentialD]x \[DifferentialD]y

(Bonus Point) Problem 3:

Find the exact volume of the solid that lies between the surfaces z = -x y (bottom face) and z = 2 - 5  (x^2) (y^2) (top face) where (x^2) + (y^2) ≤ 1.

The solid is given below:

Solution:

We denote the disc by D : (x^2) + (y^2) ≤ 1. The integral we need to compute is

∫(∫_D)(2-5(x^2)(y^2)+x y) dx dy.

We can use polar coordinates to integrate this double integral (remember to multiply the integrand by the Jacobian for polar coordinates):

(∫_0^(2  π))(∫_0^1)(2-5(r^4)(((Cos[θ]))^2) (((Sin[θ]))^2)+(r^2) Cos[θ] Sin[θ])r \[DifferentialD]r \[DifferentialD]θ

Also, we could compute the double integral using x and y:

(∫_(-1)^1)(∫_(-(Sqrt[1 - (x^2)]))^((Sqrt[1 - (x^2)])))(2-5(x^2) (y^2)+x y) \[DifferentialD]y \[DifferentialD]x

3. Triple Integrals

When a description of ℛ in terms of inequalities is available, the integral of f over ℛ can be expressed as an iterated triple integral. If ℛ can be described by inequalities of the form

φ(x, y) ≤ 
        z ≤ ψ(x, y),  u(x) ≤ y ≤ 
        v(x),  and a ≤ x ≤ b,

then the integral of f over ℛ is given by the iterated integral

\(∫\_a\%b\(∫\_\(u(x)\)\%\(v(x)\)\(∫\_\(φ(x,  y)\)\%\(ψ(x,  y)\)\(f(x, y, 
                    z)\) dz dy\ dx\)\)\).

If ℛ is described instead by

φ(y, z) ≤ 
        x ≤ ψ(y, z),  u(z) ≤ y ≤ 
        v(z),  and a ≤ z ≤ b,

then the integral of f over ℛ is given by the iterated integral

\(∫\_a\%b\(∫\_\(u(z)\)\%\(v(z)\)\(∫\_\(φ(y, \ z)\)\%\(ψ(y, \ z)\)\(f(x, y, 
                    z)\) dx dy dz\)\)\).

There are four other similar arrangements, which result from the remaining permutations of the variables.

Note that the “product” \(TraditionalForm\`dx\ dy\ dz\) may be viewed as a volume differential, \(TraditionalForm\`dV = dx\ dy\ dz\), which will take different forms in different coordinate systems.

Exercise: Evaluate \(TraditionalForm\`∫\(∫\(∫\_U\ 
            x\^2\ dx\ dy\ dz\)\)\), where U is the solid bounded by (y^(2 )) + (z^2) = 
        4  a x, (y^2) = a x, and x = 3  a. Assume that a is a positive constant. There are two possible choices for U. Work out the convex case.

Solution: We want to draw the solid bounded by the surfaces (considering a = 1)

(y^2) + (z^2) = 4  x, (y^2) =  x, x = 3.

We will use Mathematica to visualize this region, though I advise you to try this first by hand.

g = 
        ParametricPlot3D[{(1/4) ((s^2) + (t^2)), s, t}, {s, -4, 
            4}, {t, -3.5, 3.5}];
h = 
        ParametricPlot3D[{(s^2), s, t}, {s, -4, 4}, {t, -3.5, 
            3.5}];
m = 
        ParametricPlot3D[{3, s, t}, {s, -4, 4}, {t, -3.5, 
            3.5}];
Show[{g, h, m}, AxesLabel -> {"X", "Y", "Z"}, 
      ViewPoint -> {-1.670,  -0.690,  -3.500}, 
      Background -> GrayLevel[1]]

As we can see from the picture, if we decide to project the solid in the XY-plane we will obtain a region bounded by a parabola (y^2) = a x and the line x = 3  a. The top and bottom part of the solid (making reference to the XY-plane) is given implicitly by the equation (y^2) + (z^2) = 4  a x. Then

(∫_0^(3 a))(∫_(-(Sqrt[a x]))^((Sqrt[a x])))(∫_(-(Sqrt[4  a x - (y^2)]))^((Sqrt[4  a x - 
                      (y^2)])))(x^2) \[DifferentialD]z \[DifferentialD]y \[DifferentialD]x

(Bonus point) Problem 4:

A solid occupies the region that lies under the paraboloid z = (x^2) + (y^2) and above the triangle in the xy-plane bounded by the coordinate axes and the line x + y = 1.  Its mass density is given by

ρ[x_, y_, z_] := x y z

Compute the volume of the solid and its total mass.

Solution:

One way of describing the region is with the inequalities

0 ≤ y ≤ 1,  0 ≤ x ≤ 
        1 - y, and 0 ≤ z ≤ (x^2) + (y^2).

A picture of the region is given below:

Here is the volume of the solid

(∫_0^1)(∫_0^(1 - y))(∫_0^((x^2) + (y^2)))\[DifferentialD]z \[DifferentialD]x \[DifferentialD]y

and this is the mass of the solid

(∫_0^1)(∫_0^(1 - y))(∫_0^((x^2) + (y^2)))ρ[x, y, 
              z] \[DifferentialD]z \[DifferentialD]x \[DifferentialD]y

4. Parametrization of Surfaces

Parametrization of the Torus

In class we learned that the following vector function is a parametrization of a torus (obtained by rotating a circle of radius r with center at (a, 0, 0)  about the z-axis)

(Overscript[Φ, →])(u, 
          v) = ((a + r cos v) cos u, (a + r cos v) sin u, 
          r sin v), where (u, 
          v) ∈ [0, 2  π)×[0, 2  π).

We will translate this into Mathematica code to graph a torus. Select  a = 2 and r = 1.

phi[u_, v_] := {(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], 
          Sin[v]};
ParametricPlot3D[
      phi[u, v], {u, 0, 2  π}, {v, 0, 2  π}]

(Bonus point) Problem 5: Parametrization of half-cone

The cone located above the XY-plane is given by the graph of the equation z = (Sqrt[(x^2) + (y^2)]). In class we learned two parametrizations of this surface, one using x and y as parameters, and the other using trigonometric functions and radial segment. Plot these parametric representations of the cone.

These are the results you may obtain:

hcone[x_, y_] := {x, 
          y, (Sqrt[(x^2) + (y^2)])};
ParametricPlot3D[hcone[x, y], {x, -2, 2}, {y, -2, 2}, 
      ViewPoint -> {1.568,  -2.435,  0.779}, 
      Background -> GrayLevel[1]]

hcone2[r_, θ_] := {r Cos[θ], r Sin[θ], 
          r};
ParametricPlot3D[
      hcone2[r, θ], {r, 0, 5}, {θ, 0, 2  π}, 
      ViewPoint -> {1.523,  -2.424,  1.070}, 
      Background -> GrayLevel[1]]

Parametrization of the Möbius Strip (not oriented surface)

A nice website about the Möbius strip is given here. In that page you will find a parametrization of this surface. Translate that parametrization into Mathematica notation and get a graph of the Möbius strip.

Let's try now to animate this non-oriented surface.

mobius[u_, v_] := {Cos[u] + v*Cos[u/2]*Cos[u], 
          Sin[u] + v*Cos[u/2]*Sin[u], 
          v*Sin[u/2]};
mgraph = 
        ParametricPlot3D[mobius[u, v], {u, 0, 2  π}, {v, -0.3, 0.3}, 
          Axes -> False, Boxed -> False, 
          Background -> 
            RGBColor[0.819608,  0.996078,  0.780392]];

(* 
      Go back to standard output *) 
 (*
<< Default3D`
*)