VC.03 The Gradient
GIVE IT A TRY!

\(Off[General::spell]; 
Off[General::spell1]; 

    \(Off[ParametricPlot3D::ppcom]; \)\)Off[ParametricPlot::ppcom]; Off[Plot::plnr]; SetOptions[Limit, Analytic -> True];

CMView = {2.7, 1.6, 1.2};

Vector Drawer

BeginPackage["Vector3D`", "Graphics`Colors`"];

\(Axes3D::"usage" = 
      "Axes3D[a, b] creates a Graphics3D object of cartesian axes with x, y, and z running from -a/3 to a, and with axes labels b units beyond the tips of the axes.  Axes3D[a] is Axes3D[a, a/8]."; 

    \(Perpend::"usage" = 
      "Perpend[a] returns a unit vector which is perpendicular to the vector a."; \)\)Arrow::"usage" = 
      "Arrow[a] produces a 2 or 3 dimensional vector from the origin to a. \
Arrow[a, Tail -> tail] gives a vector from tail to a."; Vector::"usage" = 
      "Vector[a, b] gives a 2D or 3D vector from a to b."; ArrowHead::"usage" = 
      "ArrowHead[a, vec] produces an arrowhead with its tip placed at the \
point a, pointing in the direction of the vector vec."; Tail::"usage" = 
      "Tail -> point puts the tail of the vector at point."; Norm::"usage" = 
      "Norm[vec] returns the Euclidean length of vec."; Normalize::"usage" = 
      "Normalize[vec] returns a unit vector in the direction of vec, \
provided vec is nonzero."; Aperture::"usage" = 
      "Aperture is the ratio of the radius of the base to the length of the \
head of a vector."; TipSize::"usage" = 
      "TipSize specifies an absolute size for the inner tip length of the \
head of a vector."; TipRatio::"usage" = 
      "TipRatio is the ratio of the inner length of the arrowhead to the \
length of the shaft of a vector."; HeadRatio::"usage" = 
      "HeadRatio is the ratio of the outer length of the arrowhead to the \
length of the shaft of a vector."; HeadSize::"usage" = 
      "HeadSize specifies an absolute size for the head of a vector."; 
    ScaleFactor::"usage" = 
      "ScaleFactor specifies the amount to scale a vector in length and may \
be either a number or a pure function."; ZeroVectorPointSize::"usage" = 
      "ZeroVectorPointSize is the size of the point used to represent a \
zero vector."; Options[Vector] = 
      Options[Arrow] = 
        Options[ArrowHead] = {HeadRatio -> 0.18, 
            TipRatio -> 0.14, Aperture -> 0.3, 
            ScaleFactor -> 1, HeadType -> Polygon, 
            ShaftQ -> True, EdgesQ -> True, 
            VectorColor -> RGBColor[0, 0, 1], ShaftWidth -> 0.005, 
            ZeroVectorPointSize -> 0.01}; Begin["`Private`"]; SetOptions[ParametricPlot, AspectRatio -> Automatic]; SetOptions[Plot, AspectRatio -> Automatic]; SetOptions[Graphics, AspectRatio -> Automatic]; Axes3D[u_, v_] := 
      Graphics3D[{{Blue, Line[{{-(u/3), 0, 0}, {u, 0, 0}}]}, 
          Text["x", {u + v, 0, 0}], {Blue, 
            Line[{{0, -(u/3), 0}, {0, u, 0}}]}, 
          Text["y", {0, u + v, 0}], {Blue, 
            Line[{{0, 0, -(u/3)}, {0, 0, u}}]}, 
          Text["z", {0, 0, u + v}]}]; Axes3D[u_] := Axes3D[u, (u/8)]; Norm[a_?VectorQ] := N[(Sqrt[a . a])]; Normalize[a_?VectorQ] := If[a . a == 0, a, (a/Norm)[a]]; Perpend[a_?VectorQ] := 
      Normalize[{a[[2]], 
            -a[[1]]}] /; 
        Length[a] == 2Perpend[a_?VectorQ] := 
      Normalize[
          If[a[[1]] == 0, {1, 0, 0}, {0, 
              a[[3]], 
              -a[[2]]}]] /; 
        Length[a] == 3Base3D = 
      Table[{Cos[((2 k π)/8.) ], Sin[((2 k π)/8.) ]}, {k, 0, 
          8}]; Vector[from_?VectorQ, to_?VectorQ, opts___] := 
      Module[{sq, sw, ht, hs, hr, tr, ap, sf, vc, zvps, diff = to - from, 
            tip}, {sq, sw, ht, hs, hr, ts, tr, ap, sf, vc, zvps} = 
            {ShaftQ, ShaftWidth, HeadType, HeadSize, HeadRatio, TipSize, 
                  TipRatio, Aperture, ScaleFactor, VectorColor, 
                  ZeroVectorPointSize} /. {opts} /. Options[Vector]; 
          If[from == to, 
            Return[Graphics[{PointSize[zvps], vc, Point[from]}]]]; 
          diff = If[NumberQ[N[sf]], sf diff, sf[diff]]; tip = from + diff; 
          If[NumberQ[hs], hr = (hs/Norm)[diff]; tr = 0.75 hr]; 
          If[NumberQ[ts], tr = (ts/Norm)[diff]]; 
          Graphics[{
              If[sq, {vc, Thickness[sw], Line[{from, tip - tr diff}]}, {}], 
              With[{trans = ap hr Norm[diff] Perpend[diff]}, {vc, 
                  Thickness[sw], 
                  ht[{tip, tip - hr diff + trans, tip - tr diff, 
                      tip - hr diff - trans, tip}]}]}]] /; 
        Length[from] == Length[to] == 2Vector[from_?VectorQ, to_?VectorQ, opts___] := 
      Module[{sq, eq, sw, hs, hr, tr, ap, sf, vc, zvps, diff = to - from, 
            tip}, {sq, eq, sw, hs, hr, ap, sf, vc, zvps} = 
            {ShaftQ, EdgesQ, ShaftWidth, HeadSize, HeadRatio, Aperture, 
                  ScaleFactor, VectorColor, ZeroVectorPointSize} /. {opts}
                   /. Options[Vector]; 
          If[from == to, 
            Return[Graphics3D[{PointSize[zvps], vc, Point[from]}]]]; 
          diff = If[NumberQ[N[sf]], sf diff, sf[diff]]; tip = from + diff; 
          If[NumberQ[hs], hr = (hs/Norm)[diff]]; tr = (hr/2); 
          Graphics3D[{
              If[sq, {vc, Thickness[sw], Line[{from, tip - tr diff}]}, {}], 
              If[eq, {}, EdgeForm[]], {SurfaceColor[vc], 
                With[{temp = Perpend[diff]}, 
                  (Polygon[Append[#1, tip]]&)/@
                    Partition[
                      (tip - hr diff + #1&)/@
                        ((ap hr Norm[diff] Base3D) . {temp, 
                              Normalize[temp\[Cross]diff]}), 2, 1]]}}]] /; 
        Length[from] == Length[to] == 3Arrow[a_, Tail -> b_, opts___] := Vector[b, a + b, opts]Arrow[a_, opts___] := Vector[Table[0, {Length[a]}], a, opts]\(ArrowHead[a_, b_, opts___] := 
      Vector[a - b, a, ShaftQ -> False, opts]; 

End[]; 

    \(EndPackage[]; \)\)

Graphics`Colors`GosiaGreen = RGBColor[0,  0.392187,  0];

G.1)  The gradient points in the direction of greatest initial increase*

G.1.a)

Go with
     f[x, y, z] = Log[3  (x^2) +  (y^2) +  (z^2)].
In which direction should you leave the point {2.1, -3.7, 4.3} to get the greatest possible initial increase of f[x, y, z]?

G.1.b.i)

Set 
       f[x, y] = 2  Sin[0.3  x y] 
and look at a plot of f[x[t], y[t]] for 
       {x[t], y[t]} = {0.1, 2} +  t gradf[0.1, 2] 
and 0 ≤ t ≤ 3:

\(Clear[f, gradf, x, y, t]; 
f[x_, y_] = 2\ Sin[0.3\ x\ y]; 

    \(gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}; 
    
{x[t_], y[t_]} = {0.1, 2} + t\ gradf[0.1, 2]; 


    Plot[f[x[t], y[t]], {t, 0, 3}, 
	
      PlotStyle -> {{Blue, Thickness[0.02]}}, PlotRange -> All, 
      AxesLabel -> {"t", ""}]; \)\)

The knowledge of what fact about gradients gives you the ability to predict, before seeing the plot, that the curve must go up before it can go down? 
Experiment with other functions f[x, y].
Explain why the plot will go up initially no matter what function f[x, y] you go with as long as gradf[0.1, 2] is not {0, 0}.

G.1.b.ii)

Set 
       f[x, y, z] = 0.6  Cos[1.8  x y (z^2)] 
and look at a plot of           
       f[x[t], y[t], z[t]] 
for 
       {x[t], y[t], z[t]} = {0.3, -0.8, 1.2} -  
          t gradf[0.3, -0.8, 1.2] 
and 0 ≤ t ≤ 1:

\(Clear[f, gradf, x, y, z, t]; 

    f[x_, y_, z_] = 0.6\ Cos[1.8\ x\ y\ z\^2]; 

    \(gradf[x_, y_, z_] = {D[f[x, y, z], \ x], D[f[x, y, z], \ y], 
        D[f[x, y, z], \ z]}; 
    
{x[t_], y[t_], z[t_]} = {0.3, \(-0.8\), 1.2} - 
        t\ gradf[0.3, \(-0.8\), 1.2]; 

    \(Plot[f[x[t], y[t], z[t]], {t, 0, 1}, 
      PlotStyle -> {{Blue, Thickness[0.02]}}, 
      AxesLabel -> {"t", ""}]; \)\)\)

The knowledge of what fact about gradients gives you the ability to predict, before seeing the plot, that the curve must go DOWN before it can go up? 
Experiment with other functions f[x, y, z].
Explain why the plot will go down initially no matter what function f[x, y, z] you go with as long as gradf[0.3, -0.8, 1.2] is not {0, 0, 0}.

G.1.c.i)

Here is the curve 
       {x[t], y[t]}={Cos[t] +  1,((3  Sin[t])/2)} 
for 0 ≤ t ≤ 2  π, together with tangent vectors at the points 
       {x[(π/2)], y[(π/2)]} and {x[((3  π)/2)], y[((3  π)/2)]}
all in true-scale:

\(Clear[x, y, t]; 
{x[t_], y[t_]} = {Cos[t] + 1, \(3\ Sin[t]\)\/2}; 

    \(curveplot = 
      ParametricPlot[{x[t], y[t]}, {t, 0, 2\ π}, 
        PlotStyle -> {{Blue, Thickness[0.01]}}, 
        AxesLabel -> {"x", "y"}, 
        DisplayFunction -> Identity]; \)\)Clear[tanvect];
tanvect[t_]:=Arrow[{x'[t],y'[t]},Tail -> {x[t], y[t]},VectorColor -> Red];
setup = 
        Show[curveplot, tanvect[(π/2)], tanvect[((3 π)/2)], 
          AspectRatio -> Automatic, 
          DisplayFunction -> $DisplayFunction];

Now go with 
       f[x, y] = 4 - (((x +  1))^2) -  (y^2) 
and add to the plot the gradient vector
       gradf[x[(π/2)], y[(π/2)]] 
with tail at 
     {x[(π/2)], y[(π/2)]}
and
       gradf[x[((3  π)/2)], y[((3  π)/2)]] 
with tail at 
     {x[((3  π)/2)], y[((3  π)/2)]}. 
Remembering that
       D[f[x[t], y[t]], t]=gradf[x[t], y[t]].{x'[t],y'[t]},
use the information displayed in your plot to explain how the plot tells you that derivative 
       D[f[x[t], y[t]], t] 
is positive at the higher point and negative at the lower point.

G.1.c.ii)

Now add to the plot above the tangent vector and gradient vector at the point {x[π], y[π]}. 
Again, remembering that
       D[f[x[t], y[t]], t]=gradf[x[t], y[t]].{x'[t],y'[t]},
use what you see to explain why the derivative D[f[x[t], y[t]], t] is equal to 0 at t = π.  
Confirm what you say with a calculation of the derivative at that point.

G.1.d.i)

You can describe any line through the point {1, 1} by selecting a unit vector {a, b} and putting:
       {x[t], y[t]} = {1, 1} +  t {a, b}.
Go with 
       f[x, y] = (x^2) y 
and say how you should set a and b so that the derivative of f[x[t], y[t]] with respect to t is as big as possible when t = 0.

G.1.d.ii)

Here is a true scale plot of the level curve 
       (x^2) y = 1 
together with a line through {1, 1}:

{a, b} = {(1/2), ((Sqrt[3])/2)}; \(Clear[x, y, t]; 

    level = ContourPlot[x\^2\ y, {x, 0, 2}, {y, 0, 2}, Contours -> {1}, 
        ContourShading -> False, DisplayFunction -> Identity]; 

    \(line = ParametricPlot[{1, 1} + t\ {a, b}, {t, 0, 1}, 
        PlotStyle -> {{Red, Thickness[0.01]}}, 
        DisplayFunction -> Identity]; \)\)\(point = Graphics[{Blue, PointSize[0.04], Point[{1, 1}]}]; 


    Show[level, line, point, AspectRatio -> Automatic, 
      DisplayFunction -> $DisplayFunction]; \)

Copy, paste, and edit the code above so that it plots the line you found in the last part.
Describe what you see and explain why you see it.

G.2)  The gradient is perpendicular to the level curves and surfaces*

G.2.a)

Plot part of the level curve
       f[x, y] = y -  Sin[x] = 0  
and throw in a few normal vectors.

G.2.b)

The sphere of radius 2 centered at {1, 2, 0}  is the level surface of the function
       f[x, y, z] = 
        (((x - 1))^2) +  (((y -  2))^2) +  (z^2) = 4.
It's not easy to use f[x, y, z] to plot this sphere, but plotting it parametrically is not bad if you use:

\(Clear[s, t, sphereplotter]; 

    sphereplotter[s_, t_] = {1, 2, 0} + 
        2\ {Sin[s]\ Cos[t], Sin[s]\ Sin[t], Cos[s]}; \)

Check:

\(Clear[f, x, y, z]; 

    f[x_, y_, z_] = \((x - 1)\)\^2 + \((y - 2)\)\^2 + z\^2; 

    TrigExpand[f@@sphereplotter[s, t]]\)

Good.
Here comes the plot of the top cap of the sphere with a selection of gradient vectors 
       ∇f[x, y, z] = gradf[x, y, z] 
at some selected points on the cap:

\(Clear[gradf, gradvect]; 

    gradf[x_, y_, z_] = {D[f[x, y, z], \ x], D[f[x, y, z], \ y], 
        D[f[x, y, z], \ z]}; 

    topcap = ParametricPlot3D[
        Evaluate[sphereplotter[s, t]], {s, 0, π\/2}, {t, 0, 2\ π}, 
        DisplayFunction -> Identity]; 

    gradvect[s_, t_] := 
      Arrow[gradf@@sphereplotter[s, t], Tail -> sphereplotter[s, t]]; 

    
Show[topcap, 
	
      Table[gradvect[s, t], {t, 0, \(7\ π\)\/4, π\/4}, {s, 0, 
          π\/2, π\/4}], ViewPoint -> CMView, 
      AxesLabel -> {"x", "y", "z"}, Boxed -> False, 
      BoxRatios -> Automatic, PlotRange -> All, 
      DisplayFunction -> $DisplayFunction]; \)

Describe the relationship between the gradient vectors and the surface and explain why you could have predicted the outcome in advance.

G.2.c.i)

You are looking for the highest and lowest possible z coordinates of points {x, y, z} on a the level surface f[x, y, z] = 1 for a function f[x, y, z].
Explain:
At {(Subscript[x, 1]), (Subscript[y, 1]), (Subscript[z, 1])} on the level surface with the highest z or the lowest z coordinate, the first two slots of gradf[(Subscript[x, 1]), (Subscript[y, 1]), (Subscript[z, 1])] must be 0.

G.2.c.ii)

The points {x, y, z} on the sphere (x^2) +  (y^2) +  (z^2) = 1 with the highest and lowest z coordinates are {0, 0, 1} and {0, 0, -1}.
Here's how you use the information in part i) to make Mathematica spit these points out:

\(Clear[f, x, y, z]; 
f[x_, y_, z_] = x\^2 + y\^2 + z\^2; 

    gradf[x_, y_, z_] = {D[f[x, y, z], \ x], D[f[x, y, z], \ y], 
        D[f[x, y, z], \ z]}; 
eqn1 = f[x, y, z] == 1; 

    eqn2 = D[f[x, y, z], \ x] == 0; 
eqn3 = D[f[x, y, z], \ y] == 0; 


    Solve[{eqn1, eqn2, eqn3}]\)

The level curve 
       f[x, y] = 3  (x^2) -  x y +  (y^2) = 1
is an ellipse in 2D:

\(Clear[f, x, y]; 
f[x_, y_] = 3\ x\^2 - x\ y + y\^2; 

    \(level = 
      ContourPlot[f[x, y], {x, \(-1\), 1}, {y, \(-1.3\), 1.3}, 
        Contours -> {1}, ContourSmoothing -> True, 
        ContourShading -> False]; \)\)

Adapt the idea immediately above to nail down the points {x, y} on this ellipse with the highest and lowest y coordinates.

G.3)  The heat seeker*

G.3.a.i)

When you go with f[x, y] = 4 -  ((((x -  3))^2) +  (((y -  5))^2)), you can spot the maximizer at {3, 5}.

\(Clear[f, gradf, x, y]; 

    f[x_, y_] = 4 - \((\((x - 3)\)\^2 + \((y - 5)\)\^2)\); 

    gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}; 


    N[Solve[gradf[x, y] == {0, 0}, {x, y}]]\)

Look at this plot of gradf[x, y] at various points on the circle of radius 1 centered at the maximizer at {3, 5}:

maximizer = {3, 5}; maxpoint = {Graphics[{PointSize[0.05], Point[maximizer]}], 
        Graphics[Text["maximizer", maximizer, {0, -2}]]}; radius = 1; \(Clear[x, y, t]; 
    
{x[t_], y[t_]} = maximizer + radius\ {Cos[t], Sin[t]}; 

    \(scalefactor = 0.25; \)\)\(gradients = 
      Table[Arrow[gradf[x[t], y[t]], Tail -> {x[t], y[t]}, 
          VectorColor -> Red, \ ScaleFactor -> scalefactor], {t, 0, 
          12, 0.5}]; 

Show[maxpoint, gradients, Axes -> True]; \)

Why do you think that those scaled gradient vectors are pointing the way they are?

G.3.a.ii)

When you go with f[x, y] = (((x -  1))^2) +  (((y -  2))^2), you can spot the minimizer at {1, 2}.

\(Clear[f, gradf, x, y]; 
f[x_, y_] = \((x - 1)\)\^2 + \((y - 2)\)\^2; 

    gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}; 


    N[Solve[gradf[x, y] == {0, 0}, {x, y}]]\)

Look at this plot of -gradf[x, y] at various points on the circle of radius 0.5 centered at the minimizer, {1, 2}:

minimizer = {1, 2}; minpoint = {Graphics[{PointSize[0.04], Point[minimizer]}], 
        Graphics[Text["minimizer", minimizer, {0, -2}]]}; radius = 0.5; \(Clear[x, y, t]; 
    
{x[t_], y[t_]} = minimizer + radius\ {Cos[t], Sin[t]}; 

    scalefactor = 0.5; 

    negativegradients = 
      Table[Arrow[scalefactor\ \((\(-gradf[x[t], y[t]]\))\), 
          Tail -> {x[t], y[t]}, VectorColor -> Red, \ 
          ScaleFactor -> scalefactor], {t, 0, 12, 0.5}]; 


    Show[minpoint, negativegradients, Axes -> True]; \)

Why do you think that those scaled negative gradient vectors are pointing the way they are?

G.3.b.i) The heat seeker

The Calculus&Mathematica Missile Company is working on some primitive heat seeking devices and you are chief engineer of the TAD (Target Acquistion Division). The current problem under study is to program a device to go to  the hottest point in a temperature distribution.  
For instance, if 
       temp[x, y]=(100/(1  +  (((x  -  2.5))^2)  +  
                2 (((y  -  3.5))^2))) 
measures the temperature at a point {x, y}, then the hottest point is {2.5, 3.5} because the denominator is smallest at this point.
You can use the gradient to try to make a heat seeking device that starts at {0, 0} and tries to seek out the hottest spot {2.5, 3.5}.
Here's a look:

\(Clear[temp, gradtemp, x, y]; 

    temp[x_, y_] = 100\/\(1 + \((x - 2.5)\)\^2 + 2\ \((y - 3.5)\)\^2\); 

    gradtemp[x_, y_] = {D[temp[x, y], \ x], D[temp[x, y], \ y]}; 


    hottestpoint = {2.5, 3.5}; 
\(start = {0, 0}; \)\)hotpt = 
      Graphics[{{PointSize[0.04], Red, Point[hottestpoint]}, 
          Text["hottest", hottestpoint, {0, 4}]}]; \(startpt = 
      Graphics[{{PointSize[0.04], Blue, Point[start]}, 
          Text["start", start, {\(-1.5\), \(-1\)}]}]; 


    setup = Show[hotpt, startpt, PlotRange -> All, Axes -> True, 
        AxesOrigin -> {0, 0}, AspectRatio -> 1]; \)

The heat seeker can't tell the exact location of the hot spot, but it can sense the gradient of the temp[x, y] merely by noting the hottest direction at a point {x, y}.
If the heat seeker is at a point {x, y}, why should you program the heat seeker so that it leaves {x, y} in the direction of gradtemp[x, y]?

G.3.b.ii)

Given:
-> The heat seeker can update its direction every instant. 
-> The heat seeker is programmed so that it leaves {x, y} in the direction of gradtemp[x, y]. 
Explain why the following plot displays a good approximation of the heat seeker's actual path when the seeker starts at {0, 0}:

Clear[Derivative, x, y, t];
equationx=x'[t]==gradtemp[x[t], y[t]][[1
            ]];
equationy=y'[t]==gradtemp[x[t], y[t]][[2
            ]];

starterx = x[0] == 0;
startery = y[0] == 0; endtime = 10; \(approxsolutions = 
      NDSolve[{equationx, equationy, starterx, startery}, {x[t], y[t]}, {t, 
          0, endtime}]; 

Clear[seeker]; 

    seeker[t_] = {
        x[t] /. approxsolutions[[1]], 
        y[t] /. approxsolutions[[1]]}; 

    seekerplot = 
      ParametricPlot[seeker[t], {t, 0, endtime}, 
        PlotStyle -> {{Thickness[0.02]}}, 
        DisplayFunction -> Identity]; 


    Show[setup, seekerplot, PlotRange -> All, 
      DisplayFunction -> $DisplayFunction]; \)

G.3.b.iii)

Given:
-> The heat seeker can update its direction every instant. 
-> The heat seeker is programmed so that it leaves {x, y} in the direction of gradtemp[x, y]. 
Give a plot of the heat seeker's path when the seeker starts at 
{0, 2}.

G.3.c.i) Bad news

The people over at the assembly division tell you that the heat seeker can't be built so as to update its direction at every instant.  Instead, it will update its direction many times, but it will move on straight line segements between direction updates. Your group at TAD reacts to this information by programming the heat seeker as follows:
-> If the heat seeker is at {(Subscript[x, k - 1]), (Subscript[y, k - 1])}, then the heat seeker moves to a new point 
       {(Subscript[x, k]), (Subscript[y, k])} = {(Subscript[x, k - 1]), (Subscript[y, k - 1])} +  
          jump gradtemp[(Subscript[x, k - 1]), (Subscript[y, k - 1])]
where the jump is positive number selected by trial and error.
For appropriately small jump numbers why is this a good update?

G.3.c.ii)

Now go from theory to practice. 
Start at {0, 0} and program the heat seeker with jump = 0.1 and 20 updates:

start = {0, 0}; hotpt = 
      Graphics[{{PointSize[0.04], Red, Point[hottestpoint]}, 
          Text["hottest", hottestpoint, {0, 4}]}]; startpt = 
      Graphics[{{PointSize[0.04], Blue, Point[start]}, 
          Text["start", start, {-1.5, -1}]}]; jump = 0.1; \(updates = 20; 

Clear[next, point, k]; 

    next[{x_, y_}] = {x, y} + jump\ gradtemp[x, y]; 
\(point[0] = start; 
    \)\)\(point[k_] := \(point[k] = N[next[point[k - 1]]]\); 


    path = Graphics[{Thickness[0.01], 
          Line[Table[point[k], {k, 0, updates}]]}]; 


    Show[hotpt, startpt, path, Axes -> Automatic, 
      AxesLabel -> {"x", "y"}, AspectRatio -> Automatic]; 
    \)

Good start, but the heat seeker lost its cool.  It nearly ran right over the hottest spot without even stopping to say hello.
Reprogram it with a smaller jump and more updates:

jump = 0.04; \(updates = 40; 

Clear[next, point, k]; 

    next[{x_, y_}] = {x, y} + jump\ gradtemp[x, y]; 

point[0] = start; 

    point[k_] := \(point[k] = N[next[point[k - 1]]]\); 


    path = Graphics[{Thickness[0.01], 
          Line[Table[point[k], {k, 0, updates}]]}]; 


    Show[hotpt, startpt, path, Axes -> Automatic, 
      AxesLabel -> {"x", "y"}, AspectRatio -> Automatic]; 
    \)

This time the heat seeker got close, but it blew its cool just as it was about to accomplish its desires.
Use trial and error to program in a jump size and an update number that send the heat seeker steadily to the hot spot so it can ignite its warhead and blow that hot spot to smithereens.

G.3.c.iii)

One way to increase the efficiency of the heat seeker is to use one of the larger jump sizes at first and run it until it goes bats.  Then use the last good point generated as a new starting point with a new, reduced jump size and run again.
Try this out starting at {0, 0} on the same function as above, incorporating any additional ideas that come to you.

G.3.d)

Use jumps and updates, as above, to guide the heat seeker starting at {0, 0} to the hottest point for:

\(Clear[temp, gradtemp, x, y]; 

    temp[x_, y_] = 100\/\(1 + \((2\ x - y)\)\^2 + \((x - 1)\)\^2\)\)

G.4)  Doing 'em by hand*

Ability to do these problems is a good sign of gradient literacy.  You should be able to do them by hand over coffee with a pencil on a napkin or the back of an envelope.

G.4.a)

Lots of folks like to use the notations 
       ∇f[x, y] = gradf[x, y] 
and
       ∇f[x, y, z] = gradf[x, y, z].
Calculate the gradient ∇f[x, y] by hand for
       f[x, y] = (e^(2  x  -  3  y))
Calculate the gradient ∇f[x, y, z] by hand for
       f[x, y, z]=Cos[((x y)/z)].

G.4.b.i)

Lots of folks like to use the notations   
       (f^((1, 0)))[x, y]=∂f[x, y]/∂x=D[f[x, y], x] 
and 
       (f^((0, 1)))[x, y]=∂f[x, y]/∂y=D[f[x, y], y]
Calculate 
       ∂f[x, y]/∂x=(f^((1, 0)))[x, y]
by hand for 
       f[x, y] = (x^2) +  (y^2) +  1.

G.4.b.ii)

Calculate 
       ∂f[x, y]/∂y=(f^((0, 1)))[x, y]
by hand for 
       f[x, y] = (e^(x  -  4  y)).

G.4.b.iii)

Calculate 
       ∂f[x, y, z]/∂z=(f^((0, 0, 1)))[x, y, z]
by hand for 
     f[x, y, z] = Sin[(x^2) (y^3) (z^4)].

G.4.c)

Here is 
       ∂f[x, y]/∂x=(f^((1, 0)))[x, y]
for
       f[x, y] = (e^Sin)[x y  -  x]:

\(Clear[f, x, y]; 
f[x_, y_] = E\^Sin[x\ y - x]; 
D[f[x, y], \ x]\)

And here is
       ∂f[1.8, 0.7]/∂x=(f^((1, 0)))[1.8, 0.7]
for the same function:

D[f[x, y],  x] /. {x -> 1.8, y -> 0.7}

What does this calculation tell you about what happens to f[x, y] when you hold y at 0.7 but make x just a teensy-weensy bit bigger than 1.8?

G.4.d)

Use the total differential of 
       f[x, y, z] = x y z 
to give a hand derivation of the formula
       D[x[t] y[t] z[t], t]=x'[t] y[t] z[t]+ x[t] y'[t] z[t]+ 
                                                            x[t] y[t] z'[t].

G.4.e)

Explain why the following notation gives you nothing more than the total differential of f.  Think about the relationship between the gradient and the total differential.
       ∇f[x, y] . {dx, dy}={∂f[x, y]/∂x,∂f[x, y]/∂y}.{dx, dy}.

G.4.f) Derivative analogies

Comment on the analogy among the chain rule formulas:
-> D[f[x[t]], t]=f'[x[t]] x'[t].
-> D[f[x[t], y[t]], t]=gradf[x[t], y[t]].{x'[t],y'[t]}.
-> D[f[x[t], y[t], z[t]], t]=
	   gradf[x[t], y[t], z[t]].{x'[t],y'[t],z'[t]}.

G.4.g)

The fundamental formula of calculus and the chain rule for functions of one variable give you the clean formula
       (∫_a^b)g'[x[t]] x'[t]dt=g[x[b]] -  g[x[a]].
Use the fundamental formula of calculus and the chain rule for functions of two variables to give a clean formula for
       (∫_a^b)gradf[x[t], y[t]].{x'[t],y'[t]}dt.

How does 
       gradf[x[t], y[t]].{x'[t],y'[t]} 
relate to the derivative of 
       g[t] = f[x[t], y[t]]?

G.5)  The highest crests and the deepest dips

G.5.a)

Way back in 1958, a fellow named Beale came up with a function whose plot looks like an Alpine valley. Here is a fairly careful rendition of the plot of his function:

\(Clear[f, x, y]; 

    f[x_, y_] = 
      \((1.500 - x\ \((1 - y\^2)\))\)\^2 + 
        \((2.250 - x\ \((1 - y\^3)\))\)\^2 + 
        \((2.625 - x\ \((1 - y\^4)\))\)\^2; 

    \(Plot3D[f[x, y], {x, \(-3\), 6}, {y, \(-2\), 2}, 
      PlotPoints -> {20, 20}, PlotRange -> {0, 20}, 
      ClipFill -> None, ViewPoint -> CMView, 
      AxesLabel -> {"x", "y", "z"}]; \)\)

Look at:

\(Clear[gradf]; 
gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}; 


    candidates = Chop[NSolve[gradf[x, y] == {0, 0}]]\)

Use what you see above to locate the deepest point in this valley.

G.5.b) The banana function

Lots of folks like to call the function
       f[x, y] = 10 (((y -  (x^2)))^2) +  (((1 -  (x^2)))^2)
"Rosenbrock's banana", because its level curves look like bananas and because it was first studied by someone named Rosenbrock.  Take a look:

\(Clear[f, x, y, r, t]; 

    f[x_, y_] = 10\ \((y - x\^2)\)\^2 + \((1 - x\^2)\)\^2; 


    chiquita = 
      ContourPlot[f[x, y], {x, \(-2\), 2}, {y, \(-4\), 6}, 
        PlotRange -> {0, 50}]; \)

Here's a 3D plot of the banana function:

Plot3D[f[x, y], {x, -2, 2}, {y, -4, 6}, 
      ViewPoint -> CMView, AxesLabel -> {"x", "y", "z"}];

Note the parabolic valley running through the surface. Use gradf[x, y] to find the lowest points (= deepest dips) in this valley.
After you've got the locations, plant flagpoles at these locations so everyone can see them.

G.5.c)

Engineers at the C&M Engineering and Foundry Company are analyzing the profit per hour from a solid state reaction carried on at a high temperature t.  In their work, they come across a function like this:

\(Clear[f, x, t]; 

    f[x_, t_] = 
      \(1\/10\^18\) 
        \((10\ \((1 - 0.7\ x)\)\ x\ t\^3\ E\^\(0.01\ t\) - E\^\(0.02\ t\) - 
            5\ x\ \((1 - x)\) - 0.1\ t\^4)\)\)

You are working in the math division of C&M and in comes some e-mail from the engineers asking for the x and t that make this function as large as possible.  The engineers mention that x is a variable the engineers call "void fraction" and t is temperature at which the reaction is to run.  This function takes you aback because there is no hope in setting its gradient equal to 0 and then solving for x and t. 
You call down to the engineers and ask what reasonable ranges on the temperature t and x are.  They reply that the reaction can run at temperatures between (2200^°) and (2500^°) and x must be between 0.3 and 1.0. You thank them and then you immediately look at:

ContourPlot[f[x, t], {x, 0.3, 1.0}, {t, 2200, 2500}];

You take one look at this and say, "Yippee!" because now you know how to use Mathematica to come up with the optimal x and t.
Do it.

G.5.d.i)

Analyze the formula
       f[x, y]=((Sin[2 x]  +  Sin[3 y])/(0.5  +  (x^2)  +  (y^2))) 
and say how you know that the surface 
       z = f[x, y] 
definitely has a deepest dip and a highest crest.

G.5.d.ii)

Use contour plots, surface plots and the FindMinimum instruction to help come up with your own best estimates of the exact locations of the highest crest and the deepest dip on the surface you studied in part i) immediately above.
Once you've located them, plot the surface with flagpoles planted at the top of the highest crest and at the bottom of the deepest dip.

G.6)  Closest points, gradients and Lagrange's method

G.6.a.i)

Here's the level curve 
       f[x, y]=((((x/3)))^2)+ (y^2)=1 
shown with the point {2, 1.5}:

{a, b} = {2, 1.5}; \(Clear[f, x, y]; 
f[x_, y_] = \((x\/3)\)\^2 + y\^2; 

    \(levelcurve = 
      ContourPlot[f[x, y], {x, 0, 3}, {y, 0, 1.7}, Contours -> {1}, 
        ContourShading -> False, DisplayFunction -> Identity]; 
    \)\)\(point = Graphics[{Red, PointSize[0.08], Point[{a, b}]}]; 


    setup = Show[levelcurve, point, AspectRatio -> Automatic, 
        Axes -> True, AxesLabel -> {"x", "y"}, 
        DisplayFunction -> $DisplayFunction]; \)

The first goal is to determine the point on the level curve that is closest to the given point {a, b} = {2, 1.5}.
The distance between the point {a, b} and a point {x, y} on the level curve is 
       (Sqrt[{x -  a, y -  b} . {x -  a, y -  b}]). 
The square of the distance between the point {a, b} and a point {x, y} on the level is:

\(Clear[distsquared]; 

    distsquared[x_, y_] = {x - a, y - b} . {x - a, y - b}\)

Lagrange's method is a natural to find the point on the level curve that is closest to {a, b}:

\(Clear[gradf, graddistsquared]; 

    gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}; 

    graddistsquared[x_, y_] = {D[distsquared[x, y], \ x], 
        D[distsquared[x, y], \ y]}; 
Clear[s]; 

    candidates = 
      N[Solve[{f[x, y] == 1, gradf[x, y] == s\ graddistsquared[x, y]}]]\)

Test the viable candidates:

candidate1 = {1.82053, 0.794821}; candidate2 = {-2.98282, -0.106879}; {distsquared@@candidate1, distsquared@@candidate2}

The closest point on the level curve f[x, y] = 1 to the given point {a, b} is candidate1.
Here is candidate1 shown, in true scale, with the line that connects the given point {a, b} to the closest point on the level curve::

closest = candidate1; closestpoint = Graphics[{Blue, PointSize[0.05], Point[closest]}]; 
    \(connector = Graphics[Line[{{a, b}, closest}]]; 


    outcome = Show[setup, closestpoint, connector]; \)

The connecting line seems to be perpendicular to the level curve.
Is this an accident?  Why or why not?

G.6.a.ii)

Here is the plot immediately above shown with the gradient of f[x, y] calculated at the closest point:

Show[outcome, Arrow[gradf@@closest, Tail -> closest], 
      PlotRange -> All, AspectRatio -> Automatic];

Bingo.
Why did it have to happen this way?

G.6.b.i)

Here's the level curve 
       f[x, y] = ((((x/3)))^2) -  (y^2) = 1
shown with the point {2, 1.5}:

{a, b} = {2, 1.5}; \(Clear[f, x, y]; 
f[x_, y_] = \((x\/3)\)\^2 - y\^2; 

    \(levelcurve = 
      ContourPlot[f[x, y], {x, 3, 5}, {y, \(-1.5\), 1.5}, 
        Contours -> {1}, ContourShading -> False, 
        DisplayFunction -> Identity]; \)\)\(point = Graphics[{Red, PointSize[0.08], Point[{a, b}]}]; 


    setup = Show[point, levelcurve, AspectRatio -> Automatic, 
        Axes -> True, AxesLabel -> {"x", "y"}, 
        DisplayFunction -> $DisplayFunction]; \)

Use Lagrange's method to find the point on the level curve that is closest to the given point {a, b} = {2, 1.5} and plot, as above, the line connecting the given point to the closest point, and plot the gradient of f[x, y] calculated at the closest point with its tail at the closest point.
Say why you are not totally surprised by what the plot displays.

G.6.b.ii)

One of the GiveItaTry problems in the previous lesson brought to light the fact that if X and Y are 3D vectors, then 
       ‖X×Y‖ = 
        ‖X‖ 
          ‖Y‖ 
          |Sin[angle between]|.
Even if you didn't do that particular problem, it's a pretty good idea to know about this because it tells you that saying that two 3D vectors X and Y point in same or opposite directions is the same as saying that 
       X×Y = {0, 0, 0}. 
Now take the same function and the same point {a, b} as in part i) above:

{a, b} = {2, 1.5}; \(Clear[f, x, y]; 
f[x_, y_] = \((x\/3)\)\^2 - y\^2\)

Put:

threeDgradf[x_, y_] = {D[f[x, y],  x], D[f[x, y],  y], 0}

And look at:

\(crossproduct = Cross[threeDgradf[x, y], \(({x, y, 0} - {a, b, 0})\)]; 

    N[Solve[{f[x, y] == 1, crossproduct == {0, 0, 0}}]]\)

Explain why this gives you the same candidates you got using Lagrange's method in part i).

G.7)  The Cobb-Douglas manufacturing model for industrial engineering

Manufacturing costs are usually split into capital costs (CEO stock options, golden parachutes, limos, private jets, other overhead, equipment, etc.) and labor costs (salaries and sweat).  Manufacturers can manipulate these expenses in many ways.  They can automate heavily, or they can cut capital costs by increasing the labor force.
Economists Cobb and Douglas became famous because they noticed that if a manufacturing process uses x units of capital and y units of labor, then the output function of a manufacturing process is usually approximated by 
       f[x, y] = A (x^(k/m)) (y^((m  -  k)/m)) 
for some fixed constants A, k, and m that depend on the goods being manufactured.

\(Clear[f, x, y, A, k, m, t]; 

    f[x_, y_] = A\ x\^\(k/m\)\ y\^\(\(m - k\)\/m\)\)

This makes some sense because if you look at:

{f[t x, t y], t f[x, y]}

Then a little mental algebra revolving around the fact that 
       (t^(k/m)) (t^((m - k)/m)) = 
        (t^(k/m  +  (m - k)/m)) = (t^(m/m)) = t
tells you that
       f[t x, t y] = t f[x, y],
and this means that the output is directly proportional to the inputs of capital and labor.
In this problem, you are a big shot in The C&M Manufacturing Co., and are preparing a production run of a certain product.  The bean counters over in the finance office say that for a production run, capital costs will be $129  .15 for each unit x of capital and $95  .74 for each unit y of labor.
So the overall cost in dollars of a production run is 
       129.15  x +  95.74  y.
The company has budgeted exactly $50, 000 on this production run.
This gives you the budget line
       129.15  x +  95.74  y = 50000.
The industrial engineers have figured out that that x units of labor and y units of capital result in a production run of 
       f[x, y] = 149.2  (x^(3/4)) (y^(1/4)) units.

\(Clear[f, gradf, x, y, t]; 

    f[x_, y_] = 149.2\ x\^\(3/4\)\ y\^\(1/4\)\)

gradf[x_, y_] = {D[f[x, y],  x], D[f[x, y],  y]}

Here is a plot of the budget line 
       129.15  x +  95.74  y = 50000.
To get a useful plot of the line, pick off the two extreme possibilities:

nolabor = Solve[129.15 x + 95.74 y == 50000 /. x -> 0]

point1 = {0, 522.25}

alllabor = Solve[129.15 x + 95.74 y == 50000 /. y -> 0]

point2 = {387.15, 0}

{x[t_], y[t_]} = point1 + t (point2 - point1)

As t runs from 0 to 1, the points {x[t], y[t]} sweep out the budget line from one extreme to the other.

budgetline = 
      ParametricPlot[{x[t], y[t]}, {t, 0, 1}, 
        PlotStyle -> {{Red, Thickness[0.02]}}, 
        AspectRatio -> Automatic, AxesLabel -> {capital, labor}];

The points {x[t], y[t]} on this line represent all possible expenditures {capital, labor} that conform to the budget of $50, 000.
Find the \(\(t\^*\)\) between 0 and 1 such that production 
       f[x[t], y[t]] 
is maximized at \(t = \(t\^*\)\), and report the optimal values 
       \({x[\(t\^*\)], y[\(t\^*\)]} = {capital\ units, labor\ units}\) 
that give the most production for the given budget.

G.7.a.i)

Here are some gradient vectors gradf[x[t], y[t]] with their tails at
a choice of points {x[t], y[t]} on the line plotted above; the plot is in true scale:

\(grads = 
      Table[Arrow[gradf[x[t], y[t]], Tail -> {x[t], y[t]}], {t, 0.1, 
          0.95, 0.85\/8}]; 

    \(Show[budgetline, grads, AspectRatio -> Automatic, 
      AxesLabel -> None]; \)\)

Take the maximizing \(\(t\^*\)\) you got in in the last part and add the plot of 
       \(2  gradf[x[\(t\^*\)], y[\(t\^*\)]]\) 
with tail at \({x[\(t\^*\)], y[\(t\^*\)]}\) to the plot immediately above.

Describe what you see and then discuss the information conveyed by the plots of the other gradient vectors above.

G.7.a.ii)

Use the chain rule formula 
       D[f[x[t], y[t]], t]=gradf[x[t], y[t]].{x'[t],y'[t]} 
to explain why your plot of 
       \(gradf[x[\(t\^*\)], y[\(t\^*\)]]\) with tail at \({x[\(t\^*\)], y[\(t\^*\)]}\) 
turned out the way it did.

G.8)  Data Fit in two variables: Plucking a guitar string

The ends of a guitar string are anchored at 0 and π on the x-axis and the string is pulled to an initial position and then allowed to vibrate on its own.
Experience shows that for certain strings the function that measures the height of the string above the point x on the x-axis at time t after the pluck is well-approximated by a function of the form
       p[x, t] = 
        (Subscript[a, 1]) Sin[x] Cos[t] +  (Subscript[a, 2]) Sin[2  x] Cos[2  t] 
                     + (Subscript[a, 3]) Sin[3  x] Cos[3  t] +  …
where 0 ≤ x ≤ π, and t > 0 is time measured after the pluck. 
You use as many terms as you need for good results.
Adjustment of units can make this work for any string.
When you go with
       p[x, t] = 
        (Subscript[a, 1]) Sin[x] Cos[t] +  (Subscript[a, 2]) Sin[2  x] Cos[2  t] 
                     + (Subscript[a, 3]) Sin[3  x] Cos[3  t] +  …
then you get
       p[0, t] = (Subscript[a, 1]) Sin[0] Cos[t] +  (Subscript[a, 2]) Sin[0] Cos[2  t] 
                     + (Subscript[a, 3]) Sin[0] Cos[3  t] +  …
                     = 0
because Sin[0] = 0, and you get
       p[π, t] = 
        (Subscript[a, 1]) Sin[π] Cos[t] +  (Subscript[a, 2]) Sin[2  π] Cos[2  t] 
                     + (Subscript[a, 3]) Sin[3  π] Cos[3  t] +  …
                     = 0
because Sin[k π] = 0 no matter what integer k you go with.
The physical interpretation of 
       p[0, t] = p[π, t] = 0  
is that the wire is anchored to the x-axis at the points x = 0 and x = π.

G.8.a.i)

For p[x, t] of the above form, what is the first time t after t = 0 that the string can be counted on to return to the shape it had at t = 0?

How long before Cos[t], Cos[2  t], Cos[3  t], Cos[4  t], …
begin to repeat themselves?

G.8.a.ii)

As above the string, anchored at 0 and π on the x-axis, was plucked at t = 0 and the following data {x, p[x, 0]} measuring the height p[x, 0] of the string above position x on the x-axis at time t = 0 were collected:

pluckdata = {{0. , 0. }, {0.3, 0.03}, {0.6, 0.06}, {0.9, 0.09}, {1.2, 
          0.12}, {1.5, 0.15}, {1.8, 0.12}, {2.1, 0.10}, {2.4, 0.07}, {2.7, 
          0.04}, {3. , 0.01}, {N[π], 0. }};

Here is a plot(not in true scale).

pluckdataplot = 
      ListPlot[pluckdata, 
        PlotStyle -> {PointSize[0.02], RGBColor[0, 0, 1]}];

Fit these data (for t = 0) as well as you can by a function
       p[x, t] = (Subscript[a, 1]) Sin[x] Cos[t] 
                     + (Subscript[a, 2]) Sin[2  x] Cos[2  t]
                     + (Subscript[a, 3]) Sin[3  x] Cos[3  t].
Show your estimated shape of the string at times t = 0, (π/2), π, ((3 π)/2), and 2  π.
Plot your p[x, t] for 0 ≤ x ≤ π and 0 ≤ t ≤ 2  π.
What do the cross sections cut by planes perpendicular to the t-axis represent?

When t = 0, all the cosine factors are equal to 1; so you want to fit the data with
       (Subscript[a, 1]) Sin[x] +  (Subscript[a, 2]) Sin[2 x] +  (Subscript[a, 3]) Sin[3  x].
After you get your values of (Subscript[a, 1]), (Subscript[a, 2]), and (Subscript[a, 3]), then form your function
       p[x, t] = (Subscript[a, 1]) Sin[x] Cos[t] 
                     + (Subscript[a, 2]) Sin[2  x] Cos[2  t]
                     + (Subscript[a, 3]) Sin[3  x] Cos[3  t].

G.8.b)

Cameras are set to monitor what a vibrating string anchored at 0 and π on the x-axis is doing at positions 
       x = 1.5 and x = 2.5. 
The cameras record the string's position at 0, 1, 2, 3, 4, and 5 seconds after it was plucked.  Here is what the cameras found in the form {x, t, p[x, t]} where x is position on the x-axis, t is time after the pluck and p[x, t] is the height of the string above x at time t:

data = {{1.5, 0, 0.35}, {2.5, 0, 0.15}, {1.5, 1, 0.14}, {2.5, 1, 
          0.13}, {1.5, 2, -0.10}, {2.5, 2, -0.11}, {1.5, 3, 
          -0.34}, {2.5, 3, -0.15}, {1.5, 4, -0.17}, {2.5, 4, 
          -0.15}, {1.5, 5, 0.07}, {2.5, 5, 0.07}};

Get a good fit of these data by a function of the form
       p[x, t] = (Subscript[a, 1]) Sin[x] Cos[t] 
                     + (Subscript[a, 2]) Sin[2  x] Cos[2  t]
                     + (Subscript[a, 3]) Sin[3  x] Cos[3  t] +  …
Then give a plot of p[x, 0] to give your estimate of the shape of the initial pluck.
Finally make a movie showing how the string vibrates.

G.9)  Linearizations and total differentials*

For functions f[x] of one variable, lots of folks like to look at the linearization of f[x] at point a: 
       linearf[x, a]=f'[a](x -  a)+ f[a].
An example:

Clear[f, x, linf, a];
f[x_] = (1/3) Sin[1.7 x] - (1/4) Cos[2.1 x];
linearf[x_, a_]=f'[a] (x - a)+f[a]

Here are plots of f[x] and linearf[x, a] for a couple of points a:

a = 0.5; \(\(linplot1 = 
      Plot[{f[x], linearf[x, a]}, {x, a - 0.5, a + 0.5}, 
        PlotStyle -> {{Blue, Thickness[0.01]}, {Red, Thickness[0.01]}}, 
        AxesOrigin -> {a, f[a]}, AxesLabel -> {"x", \*""""}, 
        PlotLabel -> a\ "= a"]; \)\)

a = 1.5; \(\(linplot2 = 
      Plot[{f[x], linearf[x, a]}, {x, a - 0.5, a + 0.5}, 
        PlotStyle -> {{Blue, Thickness[0.01]}, {Red, Thickness[0.01]}}, 
        AxesOrigin -> {a, f[a]}, AxesLabel -> {"x", \*""""}, 
        PlotLabel -> a\ "= a"]; \)\)

The linearized version of f[x] at a point a is just the tangent line through {a, f[a]}, but it has some strong virtues:
-> As x varies, linearf[x, a] is much easier to calculate than f[x].
-> linearf[x, a] approximates f[x] very well for x's near a.
-> linearf[x, a] goes up if f[x] goes up as x advances through a.
-> linearf[x, a] goes down if f[x] goes down as x advances through a.
In short, if x is close to a, then linearf[x, a] mimics f[x] very well.

Lots of other folks (especially older folks) prefer to look at the differential of f[x] at a point a:
       df=f'[a]dx
They treat dx as a number and say f[a +  dx] is well approximated by f[a] +  df.
See what this means for the same function at the same points looked at above.

Clear[df, dx];
a = 0.5;
df=f'[a] dx;diffplot1 = 
      Plot[{f[a + dx], f[a] + df}, {dx, -0.5, 0.5}, 
        PlotStyle -> {{Blue, Thickness[0.01]}, {Red, Thickness[0.01]}}, 
        AxesOrigin -> {0, f[a]}, AxesLabel -> {"dx", ""}, 
        PlotLabel -> a "= a"];

Clear[df, dx];
a = 1.5;
df=f'[a] dx;diffplot2 = 
      Plot[{f[a + dx], f[a] + df}, {dx, -0.5, 0.5}, 
        PlotStyle -> {{Blue, Thickness[0.01]}, {Red, Thickness[0.01]}}, 
        AxesOrigin -> {0, f[a]}, AxesLabel -> {"dx", ""}, 
        PlotLabel -> a "= a"];

G.9.a)

Here is linplot1 compared to diffplot1:

Show[GraphicsArray[{linplot1, diffplot1}]];

Here is linplot2 compared to diffplot2:

Show[GraphicsArray[{linplot2, diffplot2}]];

Rerun for other functions and other points to get enough experience to answer the question: Is the first approach (linearizations) doing different things from the second approach (differentials), or are the two approaches doing the same thing but describing it differently?

G.9.b.i)

For functions of two or more variables, the same two approaches often persist. 
For functions f[x, y] of two variables, lots of folks like to look at the linearization of f[x, y] at point {a, b}: 
       linearf[x, y, a, b] = 
        gradf[a, b] . {x -  a, y -  b} +  f[a, b].
An example:

\(Clear[f, x, y, gradf, linearf, a, b]; 

    f[x_, y_] = 5 - 1\/2\ \((x\^2 + y\^2)\); 

    gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}\)

linearf[x_, y_, a_, b_] = gradf[a, b] . {x - a, y - b} + f[a, b]

Here is a plot showing both f[x, y] and linearf[x, y, a, b] for 
{a, b} = {-1, 1}.

{a, b} = {-1, 1}; h = 0.5; plot = 
      ParametricPlot3D[{x, y, f[x, y]}, {x, a - h, a + h}, {y, b - h, b + h}, 
        DisplayFunction -> Identity]; fplot = Insert[plot, EdgeForm[], {1, 1}]; linfplot = 
      ParametricPlot3D[{x, y, linearf[x, y, a, b]}, {x, a - h, a + h}, {y, 
          b - h, b + h}, PlotPoints -> {7, 7}, 
        DisplayFunction -> Identity]; \(linearfplot = linfplot /. Polygon -> Line; 


    both = Show[fplot, linearfplot, ViewPoint -> CMView, 
        PlotRange -> All, AxesLabel -> {"x", "y", "z"}, 
        Boxed -> False, DisplayFunction -> $DisplayFunction]; \)

See it from a different viewpoint:

newlook = 
      Show[both, ViewPoint -> {-4, 7, 4}, 
        AxesLabel -> {"x", "y", "z"}];

The two plots touch at {a, b}:

{f[x, y], linearf[x, y, a, b]} /. {x -> a, y -> b}

The curved surface is f[x, y] and the plane plastered to it at the point {a, b, f[a, b]} is the plot of linearf[x, y, a, b].
Assess the quality of the approximation of f[x, y] by linearf[x, y, a, b] as x and y vary in the vicinity of {a, b} = {-1, 1}.

The plot tells you a lot, but if you are happier with cold numbers, look at values of f[x, y] and linearf[x, y] for some points {x, y} near the point of linearization at {a, b} = {-1, 1}:

\(d\  = \ 0.2; 

    PaddedForm[
      TableForm[
        Flatten[Prepend[
            Table[{x, y, f[x, y], linearf[x, y, a, b]}, {x, a\  - \ d, 
                a\  + \ d, d}, {y, b\  - \ d, b\  + \ d, d}], {{" x", 
                " y", \ " f value", \ " linear f value"}}], 1], 
        TableAlignments -> Center], {3, 2}]\)

G.9.b.ii)

The folks who prefer differentials get in on the same act.  They take the total differential of a function f[x, y] at a point {a, b}
       df = 
        (f^((1, 0)))[a, b] dx +  
          (f^((0, 1)))[a, b] dy
            = 
        gradf[a, b] . {dx, dy}
They treat dx and dy as numbers and say
       f[a +  dx, b +  dy] 
is well approximated by 
       f[a, b] +  df.
See what this means for the same function f[x, y] at the same point you looked at above:

\(Clear[f, x, y, gradf, a, b]; 
f[x_, y_] = 5 - 1\/2\ \((x\^2 + y\^2)\); 
    
gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}\)

Here is a plot showing both 
       f[a +  dx, b +  dy] and f[a, b] +  df
for  {a, b} = {-1, 1}.

\(Clear[dx, dy, df]; 
{a, b} = {\(-1\), 1}; 

    df = gradf[a, b] . {dx, dy}\)

h = 0.5; fplotd = 
      ParametricPlot3D[{dx, dy, f[a + dx, b + dy]}, {dx, -h, h}, {dy, 
          -h, h}, DisplayFunction -> Identity]; \(dfplotd = 
      ParametricPlot3D[{a + dx, b + dy, f[a, b] + df}, {dx, \(-h\), h}, {dy, 
            \(-h\), h}, PlotPoints -> {7, 7}, 
          DisplayFunction -> Identity] /. Polygon -> Line; 


    bothd = Show[fplot, dfplotd, ViewPoint -> CMView, 
        AxesLabel -> {"dx", "dy", \*""""}, PlotRange -> All, 
        Boxed -> False, DisplayFunction -> $DisplayFunction]; \)

See it from a different viewpoint:

newlookd = Show[bothd, ViewPoint -> {-4, 7, 4}];

Look familiar?
See all four plots:

Show[GraphicsArray[{{both, bothd}, {newlook, newlookd}}]];

For functions of two variables, is the first approach (linearizations) doing different things from the second approach (differentials), or are the two approaches doing the same thing but describing it differently?
Which approach do you prefer?

G.9.c)

As you may have guessed, the guy who wrote this problem prefers the idea of linearizations to the idea of differentials, but sometimes differentials are just the ticket for making quick estimates.
Take:

\(Clear[f, gradf, x, y]; 

    f[x_, y_] = 10.4\ \((1\/3\ \((x + 2\ y)\) - \((x\ y\^2)\)\^\(1/3\))\); 

    gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}\)

You are sitting at {a, b} = {0.5, 1} and you have two choices:
-> Increase x from a to a +  dx for a small number dx.
-> Increase y from b to b +  dy for a small number dy.
To see which of these choices should you take to increase f[x, y] as much as you can, look at:

\(Clear[dx, dy, df]; 
{a, b} = {0.5, 0.1}; 

    df = N[gradf[a, b] . {dx, dy}]\)

Increasing x a little bit will drive f[x, y] up.
Increasing y a little bit will drive f[x, y] down.
Check:

dx = 0.2; dy = 0.2; {f[a + dx, b], f[a, b], f[a, b + dy]}

Yep.  To drive f[x, y] up, increase x and forget about y.
Handy little tool for making quick estimates.
You go with 
       f[x, y] = 
        128.3 +  
          608.7 (((((x^2) (y^3)))^(1/5)) -  (1/5) (2 x + 3 y))
              . 
You are sitting at {a, b} = {4.7, 2.9}  and you have two choices:
-> Increase x from a to a +  dx for a small number dx.
-> Increase y from b to b +  dy for a small number dy.
Which should you do to drive f[x, y] up?
Which should you do to drive f[x, y] down?

Tip:

You're getting tired; so as a gesture of good will and friendship, here is some code:

\(Clear[f, gradf, x, y]; 

    f[x_, y_] = 
      128.3 + 608.7\ 
          \((\(-\(1\/5\)\)\ \((2\ x + 3\ y)\) + \((x\^2\ y\^3)\)\^\(1/5\))\); 
    
gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}\)

\(Clear[dx, dy, df]; 
{a, b} = {4.7, 2.9}; 

    df = N[gradf[a, b] . {dx, dy}]\)

G.10) Keeping track of constituent costs

The location is near Pittsburgh on the bank of the Monongehela River not far from the old Westinghouse East Pittsurgh plant. 
You've got the job of shipping V cubic feet of old steel shavings across the river by barge.  To do this, you'll make a box to put the shavings in for the barge shipment.
Put
       x = length of the box in feet,
       y = width of the box in feet, and
       z = height of the box in feet.
The material for the box consists of five rectangular pieces.
The bottom has area x y; the material for it costs $a per square foot. So in dollars, 
       bottom cost = a x y.
Another two pieces (the sides) have area x z each; these cost $b per square foot.  So in dollars
       side cost  =  2 b x z. 
And the other two pieces (the ends) have area y z; these cost $c per square foot. So in dollars,
       end cost  =  2 c y z.
The tugboat captain tells us that she will charge d dollars for each trip. You have V cubic feet of shavings; so you'll'll need (V/(x y z)) trips.  So in dollars,
       transportation cost=((d V)/(x y z)).
The bottom line is 
       overall cost = 
        bottom cost +  side cost +  end cost +  
          transportation cost.
What should the ratios
       bottom 
        cost : side cost : end cost : transportation cost 
be if the overall cost is at a minimum?
Give a formula for the minimum cost and the corresponding optimal dimensions, x, y, and z, in terms of a, b, c, d, and V.
How does the minimum cost change if the captain changes her mind and charges 2  d dollars per trip?

G.11) The great pretender

G.11.a.i)

If you are dealing with a function f[x] of one variable and you find a crest at {(Subscript[x, 0]), f[(Subscript[x, 0])]} and you find that f'[x]=0 only at x = (Subscript[x, 0]), then can you be sure that (Subscript[x, 0]) maximizes f[x]?

G.11.a.ii)

If you are dealing with a function f[x] of one variable and you find a dip at {(Subscript[x, 0]), f[(Subscript[x, 0])]} and you find that f'[x]=0 only at x = (Subscript[x, 0]), then can you be sure that (Subscript[x, 0]) minimizes f[x]?

G.11.b)

Here's a plot of
       f[x, y] = (x^3) +  (e^(3  y)) -  3  x (e^y) 
in the vicinity of {1, 0}.

\(Clear[f, x, y]; 
f[x_, y_] = x\^3 + E\^\(3\ y\) - 3\ x\ E\^y; 

    \(Plot3D[f[x, y], {x, \(-0.5\), 2}, {y, \(-1.5\), 0.5}, 
      PlotRange -> {\(-1\), 1}, ViewPoint -> CMView, 
      AxesLabel -> {"x", "y", "f[x,y]"}]; \)\)

Here is a plot of some level curves of f[x, y].

ContourPlot[f[x, y], {x, -0.5, 2}, {y, -1.5, 0.5}, 
      PlotRange -> {-1, 1}];

G.11.b.i)

See the dip?
Locate the bottom of the dip by finding where the gradient of f[x, y] is {0, 0}.

\(Clear[gradf]; 
gradf[x_, y_] = {D[f[x, y], \ x], D[f[x, y], \ y]}; 


    FindRoot[gradf[x, y] == {0, 0}, {x, 0.9}, {y, \(-0.1\)}]\)

G.11.b.ii)

Look at:

gradf[x, y]

Are there any other {(Subscript[x, 0]), (Subscript[y, 0])}'s at which the gradient of 
       f[x, y] = (x^3) +  (e^(3  y)) -  3  x (e^y) 
 is {0, 0}?

G.11.b.iii)

Is the point you found in part i) a genuine minimizer of  
       f[x, y] = (x^3) +  (e^(3  y)) -  3  x (e^y)
or just a pretender?
In fact, does 
       f[x, y] = (x^3) +  (e^(3  y)) -  3  x (e^y)
even have a minimizer?

G.11.c)

True or false:
If you have a function f[x, y] with the properties that  
-> The plot of f[x, y] has a dip at {(Subscript[x, 0]), (Subscript[y, 0]), f[(Subscript[x, 0]), (Subscript[y, 0])]};
-> The only solution of 
       gradf[x, y] = {0, 0}
is x = (Subscript[x, 0]) and y = (Subscript[y, 0]),
then {(Subscript[x, 0]), (Subscript[y, 0])} is the minimizer of f[x, y].

Look at the function in the earlier parts.