Mathematica Code to

Göran Andersson, goeran@kth.se
KTH/ICT/COS
v 7.0.1

Robert A. Adams
Calculus
A Complete Course 7th Ed.

Double-click on the right bracket with the triangle below.

I  Information

This notebook refers to the text book Robert A. Adams: Calculus A Complete Course 7th Ed. It is a translation of Maple code into Mathematica code mostly written in plain Ascii without any special features.

Notice the 100% ▴ at the lower right in this window. Press ▴ to choose another magnification. This will effect both the font size and the graphics.

If this is your first contact with Mathematica read the following help links First Five Minutes with Mathematica and Notebooks and Documents and also have a look at Mathematica Documentation Center on the web. Also click on the Help tab in the menu above and choose Documentation Center and then click on Notebook Basics at Notebooks and Documents.
Please read the Preliminaries section before you select a section of your interest.

P  Preliminaries

Help link to how to define functions.

ClearAll["`*"] (* clear variables *)

P30-31

Press ⇧|[↵] after the commands.(Subscript[, ▸])]
Note: If you have a separate numerical keyboard use the ⌤ key.

f[x_]:=x^3-2x^2-12x+1

f[t]+f[1]

Plot[f[x],{x,-4,5},AxesLabel->Automatic]

Plot[f[x],{x,-4,5},AxesLabel->{HoldForm[x],HoldForm[y]},AxesLabel->Automatic]

Plot[f[x],{x,-4,5},PlotRange->{-40,30},AspectRatio->Automatic,AxesLabel->Automatic]

Mathematica is handling information in cells. The vertical extent of a cell is shown by the cell bracket (the blue one to the right. If the cell belongs to a group there is an outer group bracket. The group is opened/closed by a double-click on the group bracket. Notice that the mouse pointer is changing when you move it over the cells. Position the mouse pointer just below this cell. Notice that the pointer is horizontal. Click the mouse. You should get a horizontal line over the window. This line is showing where a new cell is created if you type characters. The cell has a default style Input which means that the cell should contain code. The style of the cell can be changed (e.g. to Text) if you select (click) the cell bracket and in the menu choose Format ⊳ Style ⊳ Text. The style of all cells is controlled by a stylesheet.
A group of cells can be executed by selecting the group bracket and the press ⇧|[↵] or ⌤. Mathematica the execute all cells with Input style in the group. 
Notice the underscore character _  (Blank) in the definition of the function f(x) above. This is a symbol for any expression. The x_ means any expression, denoted by x. The Blank symbol shoul only appear in the left hand side of the definition. The symbol := means delayed assignment, which means that the right hand side is not evaluated when the definition is made. As an example: assume that you assign t=0 then by using delayed assignment you can still make the definition g[t_]:=1/t even if t is assigned the value 0. However, it would not be possible to make the definition g[t_]=1/t.
The symbol -> is automatically created when you write -> in Input cells.

EXAMPLE 11

g[x_]:=(Abs[1+x]-1)/x;
Plot[g[x],{x,-0.5,0.5},AxesLabel->Automatic]

Plot[g[x],{x,-7*10^(-16),5*10^(-16)},AxesLabel->Automatic]

The precision of floating point numbers is normally around 16 digits.

$MachinePrecision

You can increase the working precision used by Plot with an option:

Plot[g[x],{x,-7*10^(-16),5*10^(-16)},WorkingPrecision->20,AxesLabel->Automatic]

P52-53

If you want help just position the text cursor at a Mathematica command and press F1 or enter ?command.

N[Sin[30]]
N[Sin[Pi/6]]

?N

?Sin

N[100Pi,20]
Sin[30]

Note: Mathematical two-dimensional input with Greek letters are given with escape () sequences and control codes or with palettes (menu File ⊳ Palettes). 
N[Sin[Pi/6]] can also be entered
	N[Sin[(π/6)]]
with the palette Basic Math Input or with the escape sequence
	N[Sin[pCtrl|[/]6Ctrl|[␣]]]
where  means Esc and ␣ means ␣.
In order to focus on Outputming the code in the rest of this notebook is (mostly) entered in Outputming Ascii style which is called InputForm in Mathematica. See also StandardForm and TraditionalForm. In order to switch to the traditional mathematical form select (click) the cell bracket and in the menu choose Cell ⊳ Convert to ⊳ TraditionalForm.

Now, back to the commands in the text book:

TrigExpand[Sin[5x]]

Use % to refer to the previous output.

TrigFactor[%]

TrigReduce[Cos[x]^5]

TrigReduce[Tan[4x]Sec[4x]^2]

Now, use the palette Algebraic Manipulation. In the result select (with the mouse) the denominator and press the button Simplify[◼].

1  Limits and Continuity

Help links to limits.

In the real domain when (lim_(x->a))f(x)=A exists, you usually expect that  (lim_(x->(SuperPlus[a]))) f(x)=(lim_(x->(SuperMinus[a]))) f(x)=A.
However Mathematica is working in the complex domain and Limit[f[x],x->a] is equivalent to (lim_(x->(SuperPlus[a]))) f(x) or Limit[f[x],x->a,Direction->-1].
	Limit[f[x],x->a] ⟺  Limit[f[x],x->a,Direction->-1] ⟺ (lim_(x->(SuperPlus[a]))) f(x)

ClearAll["`*"] (* clear variables *)

P76-77

The characters -> is automatically reduced to the character -> when input.

Limit[(x^2-4)/(x^2-5x+6),x->2]

Limit[(x Sin[x])/(1-Cos[x]),x->0]

Limit[x /Sqrt[x^2+1],x->-Infinity]

Limit[x /Sqrt[x^2+1],x->Infinity]

Limit[1 /x,x->0]   (* Direction->-1 is default *)

Limit[1 /x,x->0,Direction->+1]

Limit[(x^2-a^2)/Abs[x-a],x->a,Direction->+1]

Limit[(x^2-a^2)/Abs[x-a],x->a,Direction->-1]

Limit[(1+x^2)^(1/x^2),x->0]

Notice that The characters -> is automatically reduced to the character -> when input.

P85

With the following syntax the Secant method is used to solve numerical roots for a given start interval [1,2] with (notice = = for equal)

FindRoot[x^3-x-1==0,{x,1,2}]

Notice that the result here might be outside the start interval (because of the method).  If only one start value is given, e.g. {x,1.5} Newton's method is used (Adams ch. 4.2 p.222).

?FindRoot

2  Differentiation

Help link to differentiation.

The function D[f[x],x] gives a partial derivative. Mathematica has another function, called Dt, which finds total derivatives, in which all variables are assumed to be related. In mathematical notation, D[f[x],x] is like ((∂f(x))/(∂x)), while Dt[f[x],x] is like ((df(x))/(dx)).  Examples:

ClearAll["`*"] (* clear variables *)

D[a (x^3),x]

D[(x^3)+(x^2)(y^2),x, NonConstants->{y}]

D[(x^3)+(x^2)((y[x])^2),x]

Dt[a (x^3),x,Constants->{a}]

Dt[(x^3)+(x^2)(y^2),x]

P117

f[x_]:=Sqrt[1+2x^2]

f'[x]

f'[2]

D[t^2Sin[3*t],t]

Simplify[%/.{t->Pi/12}]

Note: If you want traditional form (without square brackets) just surround your expression with TraditionalForm[], e.g.

TraditionalForm[
D[t^2Sin[3t],t]
]

P128

D[x^5,x,x]+D[Sin[2x],{x,3}]

f[x_]:=x^5;
fpp[x_]=Derivative[1][Derivative[1][f]][x]

Derivative[3][f][a]

P146

deq=D[x y[x]+(y[x])^3==3,x]

sol=Solve[deq,y'[x]]

yp=y'[x]/.sol[[1]]

ypp=D[yp,x]

ypp=Simplify[ypp/.{y'[x]->yp}]

ypp/.{x->2,y[x]->1}

3  Transcendental Functions

Nothing in this chapter, but here's a help link to transcendental functions.

4  Some Applications of Derivatives

Help link to differentiation.

ClearAll["`*"] (* clear variables *)

P253

Plot[Abs[x^2-1]^(2/3),{x,-4,4},PlotRange->{-1,5},AxesLabel->Automatic]

Plot[(x^2-1)^(1/3),{x,-4,4},PlotRange->{-1,5},AxesLabel->Automatic]

EXAMPLE 11

Plot[E^x Log[1+1/E^x],{x,-20,45},PlotStyle->{Red,Thickness[0.005]},AxesLabel->Automatic]

Plot[E^x Log[1+1/E^x],{x,-20,45},PlotStyle->Dotted,AxesLabel->Automatic,PlotPoints->250]

P281

s=Sin[x];
u=Series[s,{x,0,4}]

P3=Normal[u]

Plot[s-P3,{x,-1,1}]

Plot[s-P3,{x,-0.42*10^(-3),0.42*10^(-3)},Mesh->All,PlotPoints->1000,MaxRecursion->1]

Plot[s-P3,{x,-0.42*10^(-3),0.42*10^(-3)},WorkingPrecision->25]

eps=$MachineEpsilon

N[(2^(-52))]

Plot[{s-P3,-s*eps/2,eps*s/2,-s*eps/4,eps*s/4},{x,-0.1*10^(-3),0.1*10^(-3)},PlotStyle->{Blue,Gray,Gray,Black,Black},Mesh->All]

eps

Plot[{eps (x-1)^2,eps (x-1)^2/2,-eps (x-1)^2,-eps (x-1)^2/2,(x^2-2x+1)-(x-1)^2},{x,-10^8,10^8},PlotStyle->{Black,Gray,Black,Gray,Blue},Mesh->All,PlotPoints->1500,MaxRecursion->1]

s

v=Series[s,{x,0,99}];
P99=Normal[v];

Plot[{P99,s},{x,35,39},PlotRange->{-3,3},PlotStyle->{Directive[Opacity[0.05],Blue],Black},Mesh->All,PlotPoints->500]

5  Integration

Help link to integration.

ClearAll["`*"] (* clear variables *)

P292

Sum[i^4,{i,1,n}]

Factor[%]

P356

Integrate[2^x Sqrt[1+4^x],x]

TrigToExp[%]

Integrate[2^x Sqrt[1+4^x],{x,0,Pi}]

N[%]

N[ Pi,20]

Integrate[Exp[-x^2],x]

HoldForm[Integrate[E^(-x^2),{x,-Infinity,Infinity}]]==Integrate[Exp[-x^2],{x,-Infinity,Infinity}]

NIntegrate[Sin[Cos[x]],{x,0,1}]

P384

N[Integrate[1/x,{x,1,2}],16]

N[Log[2],16]

Timing[Integrate[1/x,{x,1,2}]]

10^(-7)NSum[1/(1+i/10^7),{i,1,10^7}]

%-Log[2]

Timing[10^(-7)NSum[1/(1+i/10^7),{i,1,10^7}]]

6  Techniques of Integration

Help link to integration.

ClearAll["`*"] (* clear variables *)

P356

Integrate[2^x Sqrt[1+4^x],x]

TrigToExp[%]

Integrate[2^x Sqrt[1+4^x],{x,0,Pi}]

N[%]

N[ Pi,20]

Read about Precision.

Integrate[Exp[-x^2],x]

HoldForm[Integrate[E^(-x^2),{x,-Infinity,Infinity}]]==Integrate[Exp[-x^2],{x,-Infinity,Infinity}]

NIntegrate[Sin[Cos[x]],{x,0,1}]

Raed more about NIntegrate.

P384

N[Integrate[1/x,{x,1,2}],16]

N[Log[2],16]

Timing[Integrate[1/x,{x,1,2}]]

10^(-7)NSum[1/(1+i/10^7),{i,1,10^7}]

%-Log[2]

Timing[10^(-7)NSum[1/(1+i/10^7),{i,1,10^7}]]

7  Applications of Integration

Help link to integration.

Help links to integration.

Help link to Statistics.

Help link to differential equations.

8  Conics, Parametric Curves, and Polar Curves

Help link to plots.

ClearAll["`*"] (* clear variables *)

P470

ParametricPlot[
{t^3-3t,t^2},{t,-2,2},
PlotRange->{{-3,3},{-1,5}},
AxesLabel->{HoldForm[x],HoldForm[y]}
]

P486

PolarPlot[
1,{t,0,2Pi},
AxesLabel->{HoldForm[x],HoldForm[y]}
]

PolarPlot[
2Sin[3t],{t,0,2Pi},
AxesLabel->{HoldForm[x],HoldForm[y]}
]

PolarPlot[
{1,2Sin[3t]},{t,0,2Pi},
AxesLabel->{HoldForm[x],HoldForm[y]}
]

Note: AspectRatio->Automatic is default for PolarPlot.

9  Sequences, Series, and Power Series

Help links to Sum.

Help links to Series.

ClearAll["`*"] (* clear variables *)

P535

Sum[n^4/2^n,{n,1,Infinity}]

Sum[Exp[-n^2],{n,0,Infinity}]

N[%]

f[x_]:=Sum[x^(n-1)/n,{n,1,Infinity}]

f[x]

f[1]

f[-1]
f[1/2]

10  Vectors and Coordinate Geometry in 3-Space

Help links to Vectors and Matrices.

ClearAll["`*"] (* clear variables *)

10.8  P610

Vectors as simple lists

In Mathematica you conveniently use a List with ArrayDepth 1 to represent a vector.

u={1,2,3}

v={a,b,c}

{5,-2,3,x}

w=Array[Function[i,i^2],5]

X=Array[x,2]

Y=Array[y,4]

Note: In Mathematica parts of a list is addressed with double square brackets.

w[[4]]

Array[Function[i,3i-1],16][[10]]

X[[2]]+Y[[3]]

u+v

v-3u

u.v

Note: The Dot product is a not defined as in Maple using complex conjugate by default. In Mathematica you have to specify this, e.g.

u.Conjugate[v]

Using simple lists the dot product is commutative.

u.v==v.u

The Cross product is entered by

Cross[u,v]

Note: Cross[u,v] can also be entered u×v where the character × is entered with the escape sequence cross.

u\[Cross]v

Norm[u]

Norm[{1,-1,2,-3,1},2]

Normalize[{2,-2,1}]

u/Norm[u]

Since 𝕦·𝕧=|𝕦||𝕧|cos(θ) we have
	θ=(cos^(-1))(((𝕦·𝕧)/(|𝕦||𝕧|)))

vectorAngle[u_,v_]:=ArcCos[((u.Conjugate[v])/(Norm[u]Norm[v]))]

vectorAngle[{2,2,1},{1,-2,2}]

ExpandAll[
({2,3,1}\[Cross]{3,-2,-4}).({x,y,z}-{2,1,-1})==0
]

Clear[u,v,w]

U=Array[u,3]
V=Array[v,3]
W=Array[w,3]

Simplify[
(U\[Cross]V)\[Cross]W-(W.U)V+(W.V)U
]

Simplify[
(U\[Cross]V)\[Cross]W==(W.U)V-(W.V)U
]

Vectors as matrices

Vectors can also be introduced as column matrices or row matrices, i.e. List with ArrayDepth 2.

Uc={{1},{2},{3}}

If a matrix command is surrounded by MatrixForm you'll get a nice output.

MatrixForm[Uc]

Notice that MatrixForm is only a graphical output format. Assignments are made before applying MatrixForm.

MatrixForm[
Vc={{a},{b},{c}}
]

MatrixForm[
Ur={{1,2,3}}
]

MatrixForm[
Vr=Transpose[Vc]
]

MatrixForm[ 
Ur.Vc
]

MatrixForm[ 
Uc.Vr
]

Matrices

A matrix is introduced aa a List with ArrayDepth 2.

{{1,1,1},
{2,1,3}}

If a matrix command is surrounded by MatrixForm[] you'll get a nice output.

MatrixForm[%]

Notice that MatrixForm is only a graphical output format. Assignments are made before applying MatrixForm.

MatrixForm[
L={{1,1,1},{2,1,3}}
]

MatrixForm[M={{0,-1,-2},{1,0,-1},{2,1,0}}]

MatrixForm[
P=Array[p,{2,4}]
]

P[[1,2]]=Pi

P[[1,4]]+P[[2,4]]

MatrixForm[P]

MatrixForm[ConstantArray[0,{2,3}]]

MatrixForm[IdentityMatrix[3]]

MatrixForm[DiagonalMatrix[{a,b,c}]]

MatrixForm[
T=Transpose[L]
]

MatrixForm[L.T]
MatrixForm[T.L]

MatrixForm[
A={{1,1,1},{2,1,3},{1,1,2}}
]

detA=Det[A]

MatrixForm[
Ainv=Inverse[A]
]

Linear Equations

X=Ainv.{{2},{9},{1}}

MatrixForm[X]

Since we know that det(𝔸)=-1≠0 there is a unique solution to 𝔸·𝕏=(({{2}, {9}, {1}})). This can be found by LinearSolve.

MatrixForm[
X=LinearSolve[A,{{2},{9},{1}}]
]

L={{1,1},{2,2}}

B1={{1},{2}}

B2={{1},{1}}

Det[L]

The zero determinant means that there is no unique solution to 𝕃·𝕏=(Subscript[𝔹, 1]).If there are solutions LinearSolve finds one solution.

MatrixForm[
X=LinearSolve[L,B1]
]

All solutions are found by adding a linear combination to the vectors spanning the NullSpace. Here's how to find all solutions

Clear[t];
X1=LinearSolve[L,B1];
V=NullSpace[L];
T=Array[t,Length[V]];
X=X1+T.V;
MatrixForm[X]

Trying to solve 𝕃·𝕏=(Subscript[𝔹, 2]) with LinearSolve results in an error message of no solution.

X=LinearSolve[L,B2]

A general approach here is to form the augmented matrix (Subscript[𝕄, 1])=(𝕃|(Subscript[𝔹, 1])) or (Subscript[𝕄, 2])=(𝕃|(Subscript[𝔹, 2])) and use row reduction. Join[A,B,2] will augment by column (and Join[A,B] by row).

MatrixForm[
M1=Join[L,B1,2]
]

The row reduction is achieved by

MatrixForm[
RowReduce[M1]
]

The interpretation of the first line is 1(Subscript[x, 1])+1(Subscript[x, 2])=1, i.e. the solution set is all points on the line (Subscript[x, 1])+(Subscript[x, 2])=1. This is equivalent to the previous solution
	 𝕏=(({{(Subscript[x, 1])}, {(Subscript[x, 2])}}))=(({{1-(Subscript[t, 1])}, {(Subscript[t, 1])}}))=(({{1}, {0}}))+(Subscript[t, 1])(({{-1}, {1}}))
The second example gives

MatrixForm[
M2=Join[L,B2,2]
]

MatrixForm[
RowReduce[M2]
]

The interpretation of the second line is 0(Subscript[x, 1])+0(Subscript[x, 2])=1, i.e. 0=1, a contradiction: no solution (we have a pivot position in the last column).

Eigenvectors and Eigenfunctions

MatrixForm[
K={
{3,1,-1},
{1,4,1},
{-1,1,3}
}
]

Eigenvalues[K]

Eigenvectors[K]

MatrixForm[Transpose[%]]

See also Eigensystem.

11  Vector Functions and Curves

Help links to ParametricPlot and ParametricPlot3D.

ClearAll["`*"] (* clear variables *)

P654-655

R[t_]:={a Cos[t],a Sin[t], b t}

R[t]

R[Pi]

V[t_]:=R'[t]

V[t]

A[t_]:=V'[t]

A[t]

v[t_]:=Norm[V[t]]

v[t]

In order to simplify the expression we can use ComplexExpand which assumes that the variables are real and with TargetFunctions->{Re,Im} which will apply Re and Im rather than Abs and Arg.

ComplexExpand[v[t],TargetFunctions->{Re,Im}]

Simplify[%]

We will make our own simplify by this:

realSimplify[expr_]:=
FullSimplify[
ComplexExpand[expr,TargetFunctions->{Re,Im}],
Union[Cases[Variables[expr],_Symbol,∞]]∈Reals
]

The Union part here find the variables in the expression but let's skip the advanced part here. The following attribute makes the method work on list elements automatically.

SetAttributes[realSimplify,Listable]

An expression independent of t. Knowing this we can make a new definition

v[t_]:=realSimplify[Norm[V[t]]]

v[t]

A unit tangent vector to the curve R(t) is (𝕋 is input T)

𝕋[t_]:=realSimplify[((V[t])/(Norm[V[t]]))]

𝕋[t]

Assuming the acceleration not parallel to the velocity, you get a normal by subtracting the projection of the acceleration, i.e.

ℕ[t_]:=realSimplify[((A[t]-((A[t].V[t])/(V[t].V[t]))V[t])/(Norm[A[t]-((A[t].V[t])/(V[t].V[t]))V[t]]))]

ℕ[t]

(ℕ is input N). 
Actually, in this case the speed v(t) is constant so A(t) is normal to V(t), which means that A(t)·V(t)=0.

The binormal vector is (𝔹 is input B)

𝔹[t_]:=realSimplify[𝕋[t]\[Cross]ℕ[t]]

𝔹[t]

The curvature is

κ=realSimplify[((Norm[V[t]\[Cross]A[t]])/((Norm[V[t]])^3))]

The torsion is

τ=realSimplify[-ℕ[t].𝔹'[t]]

Here's a plot for (a,b)=(1,2).

ParametricPlot3D[
R[t]/.{a->5,b->1},{t,0,10},
AxesLabel->{HoldForm[x],HoldForm[y]}
]

It is possible to interact the picture with your mouse.
mouse[left button]		controls angles
mouse|Ctrl[left button]	controls distance

ParametricPlot3D[
R[t]/.{a->5,b->1},{t,0,10},
AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]}
]

ParametricPlot3D[
(R[t]/.{a->5,b->1}),{t,0,10},
PlotStyle->Red,
AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]}
]

ParametricPlot3D[
(R[t]/.{a->5,b->1}),{t,0,10},
ColorFunction->Function[{x,y,z},Hue[z]],
AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]}
]

12  Partial Differentiation

Help link to differentiation.

ClearAll["`*"] (* clear variables *)

P674-675

f[x_,y_]:=-6y/(2+x^2+y^2)

Plot3D[f[x,y],{x,-6,6},{y,-6,6},Boxed->False,Axes->False]

It is possible to interact the picture with your mouse.
mouse[left button]		controls angles
mouse|Ctrl[left button]	controls distance

Here's a plot with viewpoint distance 2, the angle 70° from the positive z-axis and the angle 30° from the xz-plane. The distance 2 is computed relative 1 which is the largest side of the bounding box, i.e. -0.5..0.5.
BoxRatios->Automatic gives the same scale on all axes. The character ° is input with the escape sequence deg.

vp=N[2{Sin[70°]Cos[30°],Sin[70°]Sin[30°], Cos[70°]}]

Plot3D[
f[x,y],{x,-6,6},{y,-6,6},
ViewPoint->vp,
AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]}
]

Here's a plot that corresponds to the Maple contourplot3d().

Plot3D[
f[x,y],{x,-6,6},{y,-6,6},PlotRange->All,
MeshFunctions->{Function[{x,y,z},z]},
Mesh->{Range[-2,2,0.2]},
PlotPoints->40,
AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]}
]

ContourPlot[
f[x,y],{x,-6,6},{y,-6,6},PlotRange->All,
Contours->Range[-2,2,0.2]
]

ContourPlot[(x^3)-(y^2)-5 x y-x-5==0,{x,-6,7},{y,-5,6}]

The next two plots plot correspond to the implicitplot3d examples in Maple.

ContourPlot3D[
x^2+y^2-z^2-1,{x,-4,4},{y,-4,4},{z,-3,3},
Contours->{0},(* plot f[x,y]==0 *)
MeshFunctions->{Function[{x,y,z},z]},
Mesh->{Range[-3,3,0.5]},
PlotPoints->40,
BoxRatios->Automatic,
Axes->True,AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]}
]

ContourPlot3D[
z-x^2,{x,-2,2},{y,-2,2},{z,-2,5},
Contours->{-2,0,2},
MeshFunctions->{Function[{x,y,z},x],Function[{x,y,z},y]},
Mesh->{Range[-2,2,0.2],Range[-2,2,0.2]},
BoxRatios->Automatic,Axes->True,AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]}
]

p[c_]:=ContourPlot3D[
(z^2)-(x^2)-(y^2),{x,-3,3},{y,-3,3},{z,0,2},
Contours->{2 c},
ContourStyle->RGBColor[((1+c)/2),((1-c)/2),1],
MeshFunctions->{Function[{x,y,z},z]},
Mesh->{Range[0,2,0.5]},
PlotPoints->30,
BoxRatios->{1,1,1},
Axes->True,AxesLabel->{HoldForm[x],HoldForm[y],HoldForm[z]},
ViewPoint-> 2{Sin[40°]Cos[30°],Sin[40°]Sin[30°], Cos[40°]}
]

Manipulate[p[k],{k,-1,1}]

P690-691

f[x_]:=Sin[2x]

f'[x]

Clear[f]

f[x_,y_]:=Exp[3y]Sin[2x]

D[f[x,y],x]

The following syntax is entered pdCtrl[_]xCtrl[␣]f[x,y]

(∂_x)f[x,y]

The following syntax means (∂/(∂x))f(x,y)=Derivative[1,0][f](x,y)

Derivative[1,0][f][x,y]

D[f[x,y],y]

The following syntax is entered pdCtrl[_]yCtrl[␣]f[x,y]

(∂_y)f[x,y]

The following syntax means (∂/(∂y))f(x,y)=Derivative[0,1][f](x,y)

Derivative[0,1][f][x,y]

The following syntax means ((∂^3)/(∂(x^2)∂y))f(x,y) with (x,y)=((π/4),0) or in other words Derivative[2,1][f]((π/4),0)

Derivative[2,1][f][Pi/4, 0]

D[f[x,y],{x,2},y]/.{x->(π/4),y->0}

(∂_({x,2},y))f[x,y]/.{x->(π/4),y->0}

As in Maple the partials are assumed to be continuous:

D[g[x,y],x,y]-D[g[x,y],y,x]

P700

Clear[f,g,x,y]

g[x_,y_]:=f[x^2-y^2,x y]

Simplify[Derivative[1,1][g][x,y]]

TraditionalForm[%]

P709

Clear[x,y,z,J]

J=D[{x y Exp[z], (x+2y)Cos[z]},{{x,y,z}}]

MatrixForm[J]

Notice that the syntax is

𝕁 = D[𝕗[𝕣], {𝕣}]

P723

The syntax for the gradient is

𝕘 = D[f[𝕣], {𝕣}]

Clear[f,g,x,y,z]

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

g[x_,y_,z_]=D[f[x,y,z],{{x,y,z}}]

g[2,3,-1]

Here' s an implementation of the gradient for cartesian coordinates:

ClearAll[grad,F,x,y,z];
SetAttributes[grad,HoldAll];
grad[F_][x_,y_]:=Evaluate[D[F[x,y],{{x,y}}]];
grad[F_][x_,y_,z_]:=Evaluate[D[F[x,y,z],{{x,y,z}}]]

grad[f][2,3,-1]

We can also use the Del operator (nabla).

SetAttributes[Del,HoldAll];
Del[F_]:=grad[F]

(∇f)[x,y,z]

(∇f)[2,3,-1]

There is also a Vector Analysis Package available.

Needs["VectorAnalysis`"]

Give information of the coordinate system:

SetCoordinates[Cartesian[x,y,z]]

and the use Grad:

Grad[f[x,y,z]]

P738

Here's a Taylor series expansion of cos(x+(y^2)) about (x,y)=(0,0) of order 4+4.

Series[Cos[x+y^2],{x,0,4},{y,0,4}]

Normal removes the ordo terms.

Normal[%]

Expand[%]

Collect[Normal[
Series[Cos[x+y^2],{x,Pi,4},{y,0,4}]
],{(x-Pi),y}
]

?Series

TraditionalForm[Series[f[x],{x,a,2}]]

TraditionalForm[Series[g[x,y],{x,a,2},{y,b,2}]]

13  Applications of Partial Derivatives

ClearAll["`*"] (* clear variables *)

13.7  P783

Solving Systems of Equations

FindRoot normally uses Newton´s method with derivatives.

?FindRoot

equation1=x^2+y^2==3;
equation2=x Sin[y]-y Cos[x]==0;

solution=FindRoot[{
equation1,
equation2
},
{x,1},{y,2}
]

{x0,y0}={x,y}/.solution

Here's a graph, showing the solution.

ContourPlot[
Evaluate[{equation1,equation2}],{x,-5,5},{y,-5,5},
AxesLabel->{HoldForm[x],HoldForm[y]},
PlotPoints->100,
Epilog->{Red,PointSize[0.02],Point[{x0,y0}]}
]

Giving two startvalues for each variable tells FindRoot to use the secant method, avoiding derivatives.

FindRoot[
{equation1,equation2},
{x,0,1},{y,1,2}
]

Another solution is achieved by giving other initial values.

solution2=FindRoot[
{equation1,equation2},
{x,1},{y,-2}
]

solution3=FindRoot[
{equation1,equation2},
{x,1},{y,0}
]

Notice that the last solution ((Sqrt[3]),0) is special and normally not achieved numerically by these methods (In fact we give the correct y as initial value).  If y=0 the second equation has the full x-axis as solution set.
Giving the certain initial values results in failure, because it is impossible to compute the tangent or the method diverge.

FindRoot[
{equation1,equation2},
{x,0},{y,0}
]

Example 1

(Piecewise[{{(x^2)+(y^4)==1}, {z==(x^3) y}, {(e^x)==2 y-z}}])

Let's draw surfaces from all three equations. The first equation is (y^4)+(x^2)==1

p1=ContourPlot3D[
x^2+y^4,{x,-1.5,5},{y,-1.5,1.5},{z,-1.5,1.5},Contours->{1},
Mesh->{0,0,Range[-1.5,1.5,0.5]}
]

p2=ContourPlot3D[
z-x^3 y,{x,-1.5,5},{y,-1.5,1.5},{z,-1.5,1.5},Contours->{0},
Mesh->{0,0,Range[-1.5,1.5,0.5]},PlotPoints->50
]

p3=ContourPlot3D[
Exp[x]-2y,{x,-1.5,5},{y,-1.5,1.5},{z,-1.5,1.5},Contours->{0},
Mesh->{0,0,Range[-1.5,1.5,0.5]}
]

Show[p1,p2,p3]

Rotate the picture above with your mouse. Look inside the cylinder. There are two points where all three surfaces intersect.
Below, there are two-dimensional pictures of cross-sections for different z-values. Try to move the parameter (z) so that the three different curves (different colors) intersect. We'll get two z-values -0.12 and 0.14.

eqns={(y^4)+(x^2)==1,z==(x^3) y,(E^x)==2 y-z}

system[x_,y_,z_]=eqns

Manipulate[
ContourPlot[Evaluate[system[x,y,z]],{x,-1.5,1.5},{y,-1.5,1.5},PlotLabel->z],
{z,-1,1}
]

sol1=FindRoot[eqns,{x,-1},{y,0.2},{z,-0.2}]

eqns/.sol1

sol2=FindRoot[eqns,{x,0.5},{y,0.9},{z,0.2}]

eqns/.sol2

Finding and Classifying Critical Points

Example 2

f[x_,y_]:=(x^2+x y+5y^2+x-y)Exp[-(x^2+y^2)]

f[x,y]

MatrixForm[
H=D[f[x,y],{{x,y},2}]//FullSimplify
]

Notice that the syntax is

ℍ = D[f[𝕣], {𝕣,2}]

eqns={D[f[x,y],x]==0,D[f[x,y],x]==0}

ContourPlot[
f[x,y],{x,-3,3},{y,-3,3},PlotRange->All,
Contours->Range[-1,3,0.2],
MeshFunctions->{Function[{x,y,z},x],Function[{x,y,z},y]},
Mesh->{Range[-3,3],Range[-3,3]},MeshStyle->Gray,
FrameLabel->{HoldForm[x],HoldForm[y]}
]

Plot3D[
f[x,y],{x,-3,3},{y,-3,3},
PlotRange->All,
MeshFunctions->{Function[{x,y,z},z]},
Mesh->{Range[-1,3,0.2]}
]

sol1=FindRoot[eqns,{x,0.3},{y,1}]

Eigenvalues[H/.sol1]

Both eigenvalues negative => f(x,y) has a local max

f[x,y]/.sol1

(b) The point (0,-1)

sol2=FindRoot[eqns,{x,0},{y,-1}]

Right on the spot. The solution is (0,-1).

Eigenvalues[H/.sol2]

Both eigenvalues negative => f(x,y) has a local max

f[x,y]/.sol2

(c) Near the point (-0.6,0.1)

sol3=FindRoot[eqns,{x,-0.6},{y,0.1}]

Eigenvalues[H/.sol3]

Both eigenvalues positive => f(x,y) has a local min

f[x,y]/.sol3

(d) The point (1,0)

sol4=FindRoot[eqns,{x,1},{y,0}]

Eigenvalues[H/.sol4]

The Hessian has both positive and negative eigenvalues => f(x,y) is a saddle point

f[x,y]/.sol4

(e) Near the point (-1.6,0.2)

sol5=FindRoot[eqns,{x,-1.6},{y,0.2}]

Eigenvalues[H/.sol5]

The Hessian has both positive and negative eigenvalues => f(x,y) is a saddle point

f[x,y]/.sol5

14  Multiple Integration

Help links to integration.

ClearAll["`*"] (* clear variables *)

P801

Notice that the order of  the bounds is important.

Integrate[f[x,y],{x,a,b},{y,c[x],d[x]}]

V=Integrate[a+y,{x,-a,a},{y,0,a-x^2/a}]

HoldForm[Integrate[Exp[y^3],{y,0,1},{x,0,y^2}]]==Integrate[Exp[y^3],{y,0,1},{x,0,y^2}]

See also NIntegrate.

NIntegrate[Exp[y^3],{y,0,1},{x,0,y^2}]

HoldForm[Integrate[Exp[x^3],{y,0,1},{x,0,y^2}]]==(Integrate[Exp[x^3],{y,0,1},{x,0,y^2}]//FullSimplify)

HoldForm[Integrate[Exp[x^3],{y,0,1},{x,0,y^2}]]≈NIntegrate[Exp[x^3],{y,0,1},{x,0,y^2}]

Chop replaces approximate complex numbers that are close to zero by the exact integer 0.

N[
Integrate[Exp[x^3],{y,0,1},{x,0,y^2}]
]

Chop[%]

P815  Example 9

This integral can also be computed with Boole.

(∫_(-∞)^∞)(∫_(-∞)^∞)(y/x)Boole[x≥0&&0≤y≤x&&(x^2)+4 (y^2)≤4]\[DifferentialD]y\[DifferentialD]x

However, here's a calculation where we change the variables:

Clear[f,x,y,u,v,J]

f[x_,y_]:=(y/x)

sol=Reduce[{u==(x^2)+4(y^2),v==(y/x),x>0,y>0,u>0,v>0},{x,y}]

solxy=ToRules[sol[[3;;4]]]

J=Simplify[D[{x,y}//.solxy,{{u,v}}]]

absdetJ=Simplify[Abs[Det[J]],{u≥0,v≥0}]

fuv=f[x,y]//.solxy

(∫_0^4)(∫_0^1)fuv absdetJ\[DifferentialD]v\[DifferentialD]u

Supplement

ClearAll["`*"] (* clear variables *)

Sometimes the function Boole provides a convenient way to express multi-dimensional definite integrals over regions that are not rectangles or cuboids. 
Notice that if you select the cell bracket (]) of the input cell you can change between different input forms by pressing ⇧|Ctrl[I] for InputForm, ⇧|Ctrl[N] for StandardForm and ⇧|Ctrl[T] for TraditionalForm.

Exercises 14.4   P 817

1.

(∫_(-∞)^∞)(∫_(-∞)^∞)((x^2)+(y^2)) Boole[a>0&&(x^2)+(y^2)≤(a^2)]\[DifferentialD]y\[DifferentialD]x

Notice that a>0 also informs that a∈Reals.

4.

(∫_(-∞)^∞)(∫_(-∞)^∞)Abs[x] Boole[a>0&&(x^2)+(y^2)≤(a^2)]\[DifferentialD]y\[DifferentialD]x

14.

(∫_(-∞)^∞)(∫_(-∞)^∞)Log[(x^2)+(y^2)] Boole[(x^2)+(y^2)≤1]\[DifferentialD]y\[DifferentialD]x

15.

(1/(π (a^2)))(∫_(-∞)^∞)(∫_(-∞)^∞)(Sqrt[(x^2)+(y^2)]) Boole[a>0&&(x^2)+(y^2)≤(a^2)]\[DifferentialD]y\[DifferentialD]x//Simplify

25.

(∫_(-∞)^∞)(∫_(-∞)^∞)(∫_(-∞)^∞) Boole[a>0&&(x^2)+(y^2)≤(a^2)&&(x^2)+(z^2)≤(a^2)&&(y^2)+(z^2)≤(a^2)]\[DifferentialD]z\[DifferentialD]y\[DifferentialD]x//Simplify

27.

d[x_,y_]:=Min[1-x,x+1,1-y,y+1]

(1/π)(∫_(-∞)^∞)(∫_(-∞)^∞)d[x,y] Boole[(x^2)+(y^2)≤1]\[DifferentialD]x\[DifferentialD]y//Simplify

28.

A=(∫_(-∞)^∞)(∫_(-∞)^∞)Boole[(x^2)+(y^2)≤4&&x≥1]\[DifferentialD]x\[DifferentialD]y//Simplify

xAve=(1/A)(∫_(-∞)^∞)(∫_(-∞)^∞)x Boole[(x^2)+(y^2)≤4&&x≥1]\[DifferentialD]x\[DifferentialD]y//FullSimplify

centroid=(1/A)(∫_(-∞)^∞)(∫_(-∞)^∞){x,y} Boole[(x^2)+(y^2)≤4&&x≥1]\[DifferentialD]x\[DifferentialD]y//FullSimplify

31..

(∫_(-∞)^∞)(∫_(-∞)^∞)(E^(x+y)) Boole[Abs[x]+Abs[y]≤a]\[DifferentialD]x\[DifferentialD]y//FullSimplify

35..

(∫_(-∞)^∞)(∫_(-∞)^∞)(E^((y-x)/(y+x))) Boole[x≥0&&y≥0&&x+y≤1]\[DifferentialD]x\[DifferentialD]y//FullSimplify

Exercises 14.5   P 823

1.

(∫_(-a)^a)(∫_(-b)^b)(∫_(-c)^c)(1+2 x-3 y)\[DifferentialD]z\[DifferentialD]y\[DifferentialD]x

11.

(∫_1^2)(∫_0^z)(∫_0^(y+z))(1/(((x+y+z))^3))\[DifferentialD]x\[DifferentialD]y\[DifferentialD]z

Exercises 14.6   P 830

24.

(∫_(-∞)^∞)(∫_(-∞)^∞)(∫_(-∞)^∞)((x^2)+(y^2)+(z^2)) Boole[(x^2)+(y^2)≤(a^2)&&0≤z≤h&&a>0]\[DifferentialD]x\[DifferentialD]y\[DifferentialD]z//FullSimplify

25.

(∫_(-∞)^∞)(∫_(-∞)^∞)(∫_(-∞)^∞)((x^2)+(y^2)) Boole[(x^2)+(y^2)+(z^2)≤(a^2)&&a>0]\[DifferentialD]x\[DifferentialD]y\[DifferentialD]z

15  Vector Fields

Help links to Vector Visualization.

16  Vector Calculus

Help link to Vector Analysis Package.

P901

Quit[]

Needs["VectorAnalysis`"]

SetCoordinates[Cartesian[x,y,z]]

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

G[x_,y_,z_]=Grad[f[x,y,z]]

G[1,1,1]

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

Div[F[x,y,z]]

Curl[F[x,y,z]]

H[x_,y_,z_]:={u[x,y,z],v[x,y,z],w[x,y,z]}

Div[Curl[H[x,y,z]]]

Curl[Grad[u[x,y,z]]]

Curl[Curl[H[x,y,z]]]-Grad[Div[H[x,y,z]]]+Laplacian[H[x,y,z]]

Next, we introduce the vector field 𝔽(x,y,z)=(x,y,z) trying to find the scalar potential.

F[x_,y_,z_]:={x,y,z}

The vector field is irrotational because ∇×𝔽=𝟘 (remember that ∇×(∇ϕ)=𝟘)

Curl[F[x,y,z]]=={0,0,0}

We can then try to find the scalar potential ϕ such that ∇ϕ=𝔽. There is no method for finding ϕ (as in Maple) so we have to do it manually.

F[t,0,0][[1]]

ϕ[x_,y_,z_]=(∫_0^x)F[t,0,0][[1]]\[DifferentialD]t+(∫_0^y)F[x,t,0][[2]]\[DifferentialD]t+(∫_0^z)F[x,y,t][[3]]\[DifferentialD]t+c

Grad[ϕ[x,y,z]]

Now assume that 𝔽(x,y,z)=((x^2),-x y,-x z) is given. What is the vector potential 𝔾(x,y,z).

F[x_,y_,z_]:={(x^2),-x y,-x z}

The vector field is solenoidal because ∇·𝔽=0 (remember that ∇·(∇×𝔾)=0)

Div[F[x,y,z]]==0

We can then try to find the vector potential 𝔾 such that ∇×𝔾=𝔽.

G[x_,y_,z_]:={Gx[x,y,z],Gy[x,y,z],0}

Assuming (Subscript[G, z])(x,y,z)=0.

TableForm[
eqns=Thread[Curl[G[x,y,z]]==F[x,y,z]]
]

The first equation gives

Gy[x_,y_,z_]=-∫(x^2)\[DifferentialD]z+gy[x,y]

The second equation gives

Gx[x_,y_,z_]=-∫x y\[DifferentialD]z+gx[x,y]

The third equation is

-Derivative[0,1,0][Gx][x,y,z]+Derivative[1,0,0][Gy][x,y,z]==-x z//Simplify

which gives ((∂(Subscript[g, x])(x,y))/(∂y))=((∂(Subscript[g, y])(x,y))/(∂x)). Simply choosing (Subscript[g, x])(x,y)=(Subscript[g, y])(x,y)=0 gives

gx[x_,y_]=gy[x_,y_]=0;

G[x,y,z]

The last commands in this section demonstrate the possibility of choosing another coordinate system.

SetCoordinates[Cylindrical[r,θ,z]]

Laplacian[u[r,θ,z]]

TraditionalForm[%]

17  Ordinary Differential Equations

Help links to Differential Equations.

ClearAll["`*"] (* clear variables *)

P928

DE=y''[t]+2y'[t]+5y[t]==25t+20

y[x]/.DSolve[DE,y,t]

sol=DSolve[{DE,y[0]==3,y'[0]==-2},y,t]

{y1}=y/.sol

y1[t]

N[y1[1]]

N[y1[1],50]