Problem Set 1 - #2

<< Graphics`PlotField`

Part a)

f[x_, y_] :=  {-y, x}

PlotVectorField[
        f[x, y], {x, -3, 3}, {y, -3, 3}];

PlotVectorField[f[x, y], {x, -3, 3}, {y, -3, 3}, 
        Frame -> True];

Part b)

g[x_, y_] :=  {-y, x}/(x^2 + y^2)

PlotVectorField[g[x, y], {x, -3, 3}, {y, -3, 3}, 
        Frame -> True, ScaleFactor -> 1];

Part c)

h[x_, y_] :=  {1, 1}/Sqrt[2. ]

PlotVectorField[h[x, y], {x, -3, 3}, {y, -3, 3}, 
        Frame -> True];

Part d)

Plotting fields defined in terms of polar coordinates is a little trickier.  I first define the appropriate unit vectors in terms of x and y, and then define the vector field.  (There may be an easier way to do this in Mathematica.)

rhat[x_, y_]  :=  {x, y}/
        Sqrt[x^2  +  y^2]
θhat[x_, y_] :=  {-y, x}/
        Sqrt[x^2 + y^2]
u[x_, y_] :=  2 rhat[x, y]  -  θhat[x, y]

PlotVectorField[u[x, y], {x, -3, 3}, {y, -3, 3}, 
        Frame -> True];

Problem Set 1 - #12 (Griffiths 1.11)

<< Calculus`VectorAnalysis`

SetCoordinates[Cartesian[x, y, z]]

Part a)

f[x_, y_, z_] :=  x^2  +  y^3  +  z^4

Grad[f[x, y, z]]

Part b)

f[x_, y_, z_] :=  x^2 y^3 z^4

Grad[f[x, y, z]]

Part c)

f[x_, y_, z_] :=  E^x  Sin[y] Log[z]

Grad[f[x, y, z], Cartesian[x, y, z]]

Probelm Set 1 - #13 (Griffiths 1.12)

<< Calculus`VectorAnalysis`
<< Graphics`PlotField`

Define height of hill as a funtion of x and y (i.e., east and west):

h[x_, y_] :=  
      10 (2 x y  -  3 x^2  -  4 y^2  - 18  x  +  28 y  +  
            12)

\(\(\(\(size\  = \ 4\) \);\)\ \  (*\ 
      Size\ parameter\ used\ for\ \(\(plotting\)\(.\)\)\ \ *) 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*\ \ Plots\ will\ rund\ from\ "-size"\ to\ \ \ *) \)

3-D surface plot of hill:

Plot3D[h[x, y], {x, -size, size}, {y, -size, size}, 
        PlotRange -> {0, 1000}];

Contour plot of hill:

ContourPlot[h[x, y], {x, -size, size}, {y, -size, size}, 
        PlotRange -> {0, 1000}];

ContourPlot[h[x, y], {x, -size, size}, {y, -size, size}, 
        PlotRange -> {0, 1000}, 
        ContourShading -> False];

Calculation of gradient.  (Note that the gradient is by default a 3-D vector.)

Grad[h[x, y], Cartesian[x, y, z]]

Finding position of top of hill.  (Note that I have named this calculation "sol" so
that I can use the results later.)

sol =Solve[
        Grad[h[x, y], Cartesian[x, y, z]] ==  0, {x, 
          y}]

Alternative way to specify "zero" in previous calculation:

Solve[
      Grad[h[x, y], Cartesian[x, y, z]] ==  {0, 0, 0}, {x, 
        y}]

Deternination of height of peak:

h[-2, 3]

or I can use results of previous calculation, which I gave the name "sol":

h[x, y] /. sol

Selection of first two components of gradient for a 2-D vector.  (Useful in plotting.)

grad2d  =  {Grad[h[x, y], Cartesian[x, y, z]][[1]], Grad[
            h[x, y], Cartesian[x, y, z]][[2]]}

Plot of the gradient vector:

PlotVectorField[
        grad2d, {x, -size, size}, {y, -size, 
          size}];

Grad[h[x, y], Cartesian[x, y, z]] /. {x -> 1, 
        y -> 1}

Sqrt[% . %]

N[%]

Problem Set 2 - #2 (Griffiths  1.30)

Integrate[z^2, {x, 0, 1}, {y, 0, 1 - x}, {z, 0, 1 - y - x}]

Note: Order is important.  Integration with respect to far right variable done first, and proceeds right to left.  See below, in which integration done in "wrong" order.  In this
order integration with respect to x is done first, and then x is reintroduced as a limit in subsequent integration.

Integrate[z^2, {z, 0, 1 - y - x}, {y, 0, 1 - x}, {x, 0, 1}]

"Pretty" form for integral.  You can find templates for integral signs, exponents, etc.,
in the Palletes menu, which is accessible from the pull-down File menu.

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

Problem Set 3 - #1 (Griffiths 1.28)

This is for part d) only.  I have parametrized vector and path in terms of x.

v[x_] :=  {x^2,  2  x^2, x^2}
l[x_] :=  {x, x, x}

Integrate[v[x] . l'[x], {x, 0, 1}]

or

(∫_0^1) v[x] . l'[
              x] \[DifferentialD]x

Problem Set 4 - #1 (Griffiths 1.15)

<<Calculus`VectorAnalysis`

SetCoordinates[Cartesian[x, y, z]]

Part a)

v[x_, y_, z_] := {x^2,  3  x z^2,  - 2 x z}

Div[v[x, y, z]]

Part b)

v[x_, y_, z_] := {x y,  2 y z,  3 z x}

Div[v[x, y, z], Cartesian]

Part c)

v[x_, y_, z_] := {y^2,  2 x y  +  z^2,   2  y z}

Div[v[x, y, z]]

Problem Set 4 - #2 (Griffiths 1.18)

<<Calculus`VectorAnalysis`

SetCoordinates[Cartesian[x, y, z]]

Part a)

v[x_, y_, z_] := {x^2,  3  x z^2,  - 2 x z}

Curl[v[x, y, z]]

Part b)

v[x_, y_, z_] := {x y,  2 y z,  3 z x}

Curl[v[x, y, z], Cartesian]

Part c)

v[x_, y_, z_] := {y^2,  2 x y  +  z^2,   2  y z}

Curl[v[x, y, z]]

Problem Set 4 - #3 (Griffiths 1.31)

<< Calculus`VectorAnalysis`

SetCoordinates[Cartesian[x, y, z]]

This is for part c) only.  I have parametrized vector and path in terms of x.

t[x_, y_, z_] :=   x^2  +  4 x y  +  
        2 y z^3
l[x_] :=  {x, x, x^2}

Calculate the RHS of the Fundamental Theorem:

t[1, 1, 1]  -  t[0, 0, 0]

This is the gradient:

Grad[t[x, y, z]]

This gives the gradient, but substitutes x for y, and x^2 for z:

Grad[t[x, y, z]] /. {y -> x, z -> x^2}

This is the line integral that gives LHS of fundamental theorem:

Integrate[(Grad[t[x, y, z]] /. {y -> x, 
              z -> x^2}) . l'[x], {x, 0, 1}]

or

(∫_0^1) (Grad[
                  t[x, y, z]] /. {y -> x, z -> x^2}) . l'[
              x] \[DifferentialD]x

Problem Set 4 - #4 (Griffiths 1.32)

<< Calculus`VectorAnalysis`

SetCoordinates[Cartesian[x, y, z]]

v[x_, y_, z_] :=  {x y,  2 y z,  3 z x}

Div[v[x, y, z]]

I am just going to do the volume integral:

Integrate[Div[v[x, y, z]], {x, 0, 2}, {y, 0, 2}, {z, 0, 2}]

Problem Set 4 - #6 (Griffiths 1.53)

<< Calculus`VectorAnalysis`

SetCoordinates[Spherical[r, θ, ϕ]]

v[r_, θ_, ϕ_] :=  {r^2 Cos[θ],  
        r^2 Cos[ϕ],  -r^2 Cos[θ] Sin[ϕ]}

Div[v[r, θ, ϕ]]

I am just going to do the volume integral:

Integrate[
      Div[v[r, θ, ϕ]] r^2 Sin[θ], {r, 0, R}, {θ, 
        0, π/2}, {ϕ, 0, π/2}]