Notebook giving examples of
use of partial derivatives,
maximization and contour
plotting---useful for material
in Chapter 4 of Boas
Partial derivatives---using "D"
Partial deriv w.r.t. x
D@Sin@x + y^2D, xD
CosAx + y2E
and w.r.t. y
D@Sin@x + y^2D, yD
2 y CosAx + y2E
or both together
D@Sin@x + y^2D, 88x, y<, 1<D
9CosAx + y2E, 2 y CosAx + y
2E=
Second derivatives (partial w.r.t x first, then mixed partial, then mixed partial again, then second wr.t. y)
D@Sin@x + y^2D, 88x, y<, 2<D �� MatrixForm
-Sin@x + y2D -2 y Sin@x + y2D-2 y Sin@x + y2D 2 Cos@x + y2D - 4 y2 Sin@x + y2D
Taylor series with more than one variable
Expanding about the origin:
The O[y]^7 etc. terms tell us the size of the next terms in the expansion
Series@Cos@x + yD, 8x, 0, 5<, 8y, 0, 5<D
1 -y2
2
+y4
24
+ O@yD6+ -y +
y3
6
-y5
120
+ O@yD6x +
-1
2
+y2
4
-y4
48
+ O@yD6x2
+y
6
-y3
36
+y5
720
+ O@yD6x3
+
1
24
-y2
48
+y4
576
+ O@yD6x4
+ -y
120
+y3
720
-y5
14400
+ O@yD6x5
+ O@xD6
If you don’t want to see the missing terms you can truncate using “Normal”
Normal@%42D
1 -x2
2
+x4
24
+ -x +x3
6
-x5
120
y + -1
2
+x2
4
-x4
48
y2
+
x
6
-x3
36
+x5
720
y3
+1
24
-x2
48
+x4
576
y4
+ -x
120
+x3
720
-x5
14400
y5
Another example:
Normal@Series@x Log@1 + x y^2D, 8x, 0, 6<, 8y, 0, 6<DD
x2y2
-x3y4
2
+x4y6
3
Expanding about a different point (here (1,1)):
Normal@Series@x Log@1 + x y^2D, 8x, 1, 4<, 8y, 1, 4<DD3
8
H-1 + xL2-
1
12
H-1 + xL3+
5
192
H-1 + xL4+
1 +3
2
H-1 + xL +1
4
H-1 + xL2-1
8
H-1 + xL3+
1
16
H-1 + xL4 H-1 + yL +
1 - x
4
-1
4
H-1 + xL2+
1
16
H-1 + xL3 H-1 + yL2+
-1
6
+1 - x
6
+1
8
H-1 + xL2+
1
24
H-1 + xL3-
5
96
H-1 + xL4 H-1 + yL3+
1
8
+1
4
H-1 + xL +1
32
H-1 + xL2-
3
32
H-1 + xL3+
5
128
H-1 + xL4 H-1 + yL4+
Log@2D + H-1 + xL1
2
+ Log@2D
Implicit differentiation
Example of 4.6 #2
We are asked to find dy/dx given that
y Exp[x y]=Sin[x]
This seems to require 2 steps. First, differentiating the implicit definition of y[x]
2 Partial.nb
D@y@xD Exp@x y@xDD � Sin@xD, xDãx y@xD
y¢@xD + ã
x y@xDy@xD Hy@xD + x y
¢@xDL � Cos@xD
and then solving for y':
Solve@%, 8y'@xD<D
::y¢@xD ® -ã-x y@xD H-Cos@xD + ãx y@xD
y@xD2L1 + x y@xD
>>
Finding maxima and minima
Example 4.10 #9: extremizing a function within a region
We are asked to find the maximum of 2x^2-3y^2-2x within the circle of radius 1.
FindMaximum gives wrong answer if don't give a starting point:
FindMaximum@82 x^2 - 3 y^2 - 2 x, x^2 + y^2 £ 1<, 8x, y<D91.00688 ´ 10
-8, 9x ® 1., y ® -1.14485 ´ 10
-14==
To get the correct answer need to input a negative starting x:
FindMaximum@82 x^2 - 3 y^2 - 2 x, x^2 + y^2 £ 1<, 88x, -.5<, 8y, 0<<D84., 8x ® -1., y ® 0.<<
If don't give a starting guess then get only one of the possible minima:
FindMinimum@82 x^2 - 3 y^2 - 2 x, x^2 + y^2 £ 1<, 8x, y<D8-3.2, 8x ® 0.2, y ® 0.979796<<
Get other minimum by giving a starting point with negative y:
FindMinimum@82 x^2 - 3 y^2 - 2 x, x^2 + y^2 £ 1<, 88x, 0<, 8y, -1<<D8-3.2, 8x ® 0.2, y ® -0.979796<<
Clarify situation by making contour plot
contplot = ContourPlot@2 x^2 - 3 y^2 - 2 x, 8x, -1, 1<,8y, -1, 1<, FrameLabel ® Automatic, ContourLabels ® TrueD;
boundplot = ContourPlot@x^2 + y^2 � 1, 8x, -1, 1<,8y, -1, 1<, FrameLabel ® Automatic, ContourStyle ® 8Thick, Black<D;
Partial.nb 3
Show@contplot, boundplotD
-3
-3-2
-2
-1
-1
0
1
2
3
-1.0 -0.5 0.0 0.5 1.0
-1.0
-0.5
0.0
0.5
1.0
x
y
This shows the dependence of the function along the boundary (either the top or the bottom half) show-
ing the minima at x=0.2
Plot@2 x^2 - 3 H1 - x^2L - 2 x, 8x, -1, 1<, PlotStyle ® 8Thick, Red<D
-1.0 -0.5 0.5 1.0
-3
-2
-1
1
2
3
4
Here’s another way of visualizing the problem, with a 3D contour plot.
The “RegionFunction” restricts the plot to the desired circle in x & y.
4 Partial.nb
ContourPlot3D@z == 2 x^2 - 3 y^2 - 2 x, 8x, -1, 1<, 8y, -1, 1<,8z, -4, 4<, RegionFunction ® Function@8x, y, z<, x^2 + y^2 £ 1DD
-1.0
-0.5
0.0
0.5
1.0
-1.0
-0.5
0.0
0.5
1.0
-4
-2
0
2
4
Example 4.13 #17 --- constrained minimization
Find position of minimum distance to the origin along the surface x=yz+10
Turns out there are two such positions:
FindMinimum with no starting point gives one of the two solutions:
FindMinimum@8x^2 + y^2 + z^2, x � y z + 10<, 8x, y, z<D819., 8x ® 1., y ® -3., z ® 3.<<
With a starting guess we can find the other minimum:
FindMinimum@8x^2 + y^2 + z^2, x � y z + 10<, 88x, 1<, 8y, 1<, z<D819., 8x ® 1., y ® 3., z ® -3.<<
Here we solve for x using the constraint and contour the distance vs. y and z. The two minima are clear
and also the saddle point at the origin.
Partial.nb 5
ContourPlot@Sqrt@Hy z + 10L^2 + y^2 + z^2D, 8y, -5, 5<,8z, -5, 5<, FrameLabel ® Automatic, ContourLabels ® TrueD
5
5
10
10
10
10
10
15
15
15
15
20
20
25
25
30
30
-4 -2 0 2 4
-4
-2
0
2
4
y
z
Another way of visualizing the function, though it’s hard to see exactly where the minumum distance
points are.
ContourPlot3D@x == y z + 10, 8x, -5, 5<, 8y, -5, 5<, 8z, -50, 50<, AxesLabel ® 8x, y, z<D
-5
0
5
x
-5 0 5
y
-50
0
50
z
6 Partial.nb