19
Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1. Introduction 2. Volumes of revolution 3. Solving systems of equations 4. Partial fraction decomposition 5. Direction fields 6. Solutions of differential equations 7. Eulers Method 8. Maclaurin and Taylor series 9. Graphs in polar coordinates 10. Vectors 11. Graphing lines in 3-dimensional space 12. Graphing planes 1 . I n t r o d u c t i o n Basic plotting, solutions of equations, lists and tables, defining and evaluating functions, limits, deriva- tives, and integrals are covered in the guide to Mathematica for Calculus I. This notebook covers additional topics which are useful in Calculus II. 2 . Volumes of Revolution 2.1. Plot the surface generated by revolving the graph of e -x from x = 0 to x = 1 around the y-axis.

Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Mathematica for Calculus II (Version

9.0)C. G. Melles

Mathematics Department

United States Naval Academy

December 31, 2013

Contents1. Introduction

2. Volumes of revolution

3. Solving systems of equations

4. Partial fraction decomposition

5. Direction fields

6. Solutions of differential equations

7. Euler’s Method

8. Maclaurin and Taylor series

9. Graphs in polar coordinates

10. Vectors

11. Graphing lines in 3-dimensional space

12. Graphing planes

1. Introduction

Basic plotting, solutions of equations, lists and tables, defining and evaluating functions, limits, deriva-

tives, and integrals are covered in the guide to Mathematica for Calculus I. This notebook covers

additional topics which are useful in Calculus II.

2. Volumes of Revolution

2.1. Plot the surface generated by revolving the graph of e-x from x = 0 to x = 1 around the y-axis.

Page 2: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

RevolutionPlot3D[Exp[-x], {x, 0, 1}]

2.2. Plot the surface generated by revolving the graph of sin (x) from x = 0 to x = π around the x-axis. N

Note: The arrow is → obtained by typing - and >.

RevolutionPlot3D[Sin[x], {x, 0, Pi}, RevolutionAxis → {1, 0, 0}]

2.3. Plot the solid obtained by revolving the region bounded by the graphs of y=Sqrt[x] and y=x4 around

the x-axis. Show with the same scale on both axes. Color the top surface green and the bottom

surface blue.

2 Mathematica for Calculus II Notebook 9_0.nb

Page 3: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

RevolutionPlot3D[{{Sqrt[x]}, {x^4}}, {x, 0, 1}, AspectRatio → Automatic,

RevolutionAxis → {1, 0, 0}, PlotStyle → {Green, Blue}]

2.4. Plot the same solid as in the previous example, but make the green surface partly transparent and

remove the mesh.

Mathematica for Calculus II Notebook 9_0.nb 3

Page 4: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

RevolutionPlot3D[{{Sqrt[x]}, {x^4}}, {x, 0, 1}, AspectRatio → Automatic,

RevolutionAxis → {1, 0, 0}, PlotStyle → {{Opacity[.6], Green}, Blue}, Mesh → None]

2.5. Plot the same solid again, but revolved only 3/4 way around the axis, to see a cross-section.

4 Mathematica for Calculus II Notebook 9_0.nb

Page 5: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

RevolutionPlot3D{{Sqrt[x]}, {x^4}},

{x, 0, 1}, θ, Pi 2, 2 * Pi, AspectRatio → Automatic,

RevolutionAxis → {1, 0, 0}, PlotStyle → {Green, Blue}, Mesh → None

3. Solving systems of equations

3.1. Solve the system of equations a + b + c = 2, a + d = 4, 2 a + c = 1, and 2 b - d = 1.

Notice the double == signs in the Mathematica command. Note that if the variables have been assigned values in a previous problem, you should first use the clear command to clear out previous values.

Clear[a, b, c, d]

Solve[a + b + c ⩵ 2 && a + d ⩵ 4 && 2 a + c ⩵ 1 && 2 b - d ⩵ 1, {a, b, c, d}]

{{a → 1, b → 2, c → -1, d → 3}}

3.2. Solve a system of nonlinear equations.

Solvea^2 + b^2 ⩵ 2 && b * a^2 + 1 ⩵ 0, {a, b}

a → -ⅈ, b → - 3 , a → -ⅈ, b → 3 , a → ⅈ, b → - 3 ,

a → ⅈ, b → 3 , a → - 2 , b → 0, a → 2 , b → 0

3.3. Find the real solutions of a system of nonlinear equations.

Mathematica for Calculus II Notebook 9_0.nb 5

Page 6: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Solvea^2 + b^2 ⩵ 2 && b * a^2 + 1 ⩵ 0, {a, b}, Reals

a → - 2 , b → 0, a → 2 , b → 0

3.4. Numerically approximate the real solutions of a system of nonlinear equations.

NSolvea^2 + b^2 ⩵ 2 && b * a^2 + 1 ⩵ 0, {a, b}, Reals

{{a → -1.41421, b → 0}, {a → 1.41421, b → 0}}

3.5. Find the solutions with a variable restricted to an interval.

NSolvea^2 + b^2 ⩵ 2 && b * a^2 + 1 ⩵ 0 && 0 < a < 2, {a, b}, Reals

{{a → 1.41421, b → 0}}

4. Partial fraction decomposition

4.1. Find the partial fraction decomposition of a rational function.

Apart3 x^2 - x + 4 x^3 + 4 x

1

x+-1 + 2 x

4 + x2

5. Direction fields

5.1. Plot a direction field for the differential equation y’=-x/y. Since Mathematica does not have a

function to plot direction fields, we use the VectorPlot function to plot the vector field {1,-x/y}. We use

the VectorScale options Tiny (size of vectors relative to bounding boxes), Automatic (aspect ratio),

and None (all vectors the same length). We use VectorStyle “Segment”.

VectorPlot[{1, -x / y}, {x, -3, 3}, {y, -3, 3},

VectorScale → {Tiny, Automatic, None}, VectorStyle → "Segment"]

-3 -2 -1 0 1 2 3

-3

-2

-1

0

1

2

3

6 Mathematica for Calculus II Notebook 9_0.nb

Page 7: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

5.2. We plot another vector field, using options to obtain a more detailed picture. We give the plot a

name, such as Field2, for use below in section 6.

Field2 = VectorPlot1, y * 3 - y, {x, 0, 4}, {y, 0, 4}, VectorPoints → Fine,

VectorScale → {0.02, Automatic, None}, VectorStyle → "Segment"

0 1 2 3 4

0

1

2

3

4

6. Solutions of differential equations

6.1. Solve a differential equation exactly. C[1] represents an unknown constant.

DSolve[y'[x] ⩵ -x / y[x], y[x], x]

y[x] → - -x2 + 2 C[1] , y[x] → -x2 + 2 C[1]

6.2. Solve a differential equation with initial condition.

DSolve[{y'[x] ⩵ -x / y[x], y[0] ⩵ 2}, y[x], x]

DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution.

y[x] → 4 - x2

6.3. Solve a differential equation and plot the solution. We save the result of the DSolve command with a

name of our choice, such as Solution1. The ; at the end of the first command indicates not to display

the result. The /. in the second command indicates that Solution1 is to be used for y[x].

Mathematica for Calculus II Notebook 9_0.nb 7

Page 8: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Solution1 = DSolvey'[x] ⩵ y[x] * 3 - y[x], y[0] ⩵ 0.1, y[x], x;

Plot[y[x] /. Solution1, {x, 0, 4}]

Solve::ifun :

Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

1 2 3 4

0.5

1.0

1.5

2.0

2.5

3.0

6.4. Solve the same differential equation numerically and plot it.

Solution2 = NDSolvey'[x] ⩵ y[x] * 3 - y[x], y[0] ⩵ 0.1, y, {x, 0, 4};

Plot[y[x] /. Solution2, {x, 0, 4}]

1 2 3 4

0.5

1.0

1.5

2.0

2.5

3.0

6.5. Find solutions of a differential equation for several initial conditions and plot them. We first construct

a list of replacement rules for the initial conditions, which we give a name, such as c3list. We then

solve the differential equation and give it a name, such as Solution3. Using /. we evaluate y[x] at

these solutions and at each of the constants, to form a list of solutions, which we can then plot.

c3list = Table[{c3 → c}, {c, {0, 0.1, 1, 2, 3, 4}}];

Solution3 = DSolvey'[x] ⩵ y[x] * 3 - y[x], y[0] ⩵ c3, y[x], x;

Solve::ifun :

Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Solutionlist3 = y[x] /. Solution3 /. c3list

{0}, 0.3 ⅇ3 x

2.9 + 0.1 ⅇ3 x,

3 ⅇ3 x

2 + ⅇ3 x,

6 ⅇ3 x

1 + 2 ⅇ3 x, {3},

12 ⅇ3 x

-1 + 4 ⅇ3 x

8 Mathematica for Calculus II Notebook 9_0.nb

Page 9: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Plot[Solutionlist3, {x, 0, 4}]

1 2 3 4

1

2

3

4

6.6. We solve the same problem with the numerical differential equation solver. We give the plot a name,

such as SolutionPlot4. We use PlotStyle->Thick to make the plot clearer.

c4list = {0, 0.1, 1, 2, 3, 4};

Solutions4 =

TableNDSolvey'[x] ⩵ y[x] * 3 - y[x], y[0] ⩵ c4, y, {x, 0, 4}, {c4, c4list};

SolutionPlot4 = Plot[y[x] /. Solutions4, {x, 0, 4}, PlotStyle → Thick]

1 2 3 4

1

2

3

4

6.7. We combine the direction field from 5.2 with the solution plot above.

Mathematica for Calculus II Notebook 9_0.nb 9

Page 10: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Show[Field2, SolutionPlot4]

0 1 2 3 4

0

1

2

3

4

7. Euler’s methods

7.1. Apply Euler’s method to the differential equation y’=y(3-y), y(0)=0.1 with step size h=0.2 and 20

steps. Make a table of x and y values and call it EulerList1. Plot the values using ListPlot.

Clear[x, y]; x[0] = 0; y[0] = 0.1; h = 0.2;

y[i_] := y[i] = y[i - 1] + h * y[i - 1] * 3 - y[i - 1]

x[i_] := x[i] = x[i - 1] + h

EulerList1 = Table[{x[i], y[i]}, {i, 0, 20}];

10 Mathematica for Calculus II Notebook 9_0.nb

Page 11: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

TableForm[EulerList1, TableHeadings → {None, {"x", "y"}}]

x y0 0.10.2 0.1580.4 0.2478070.6 0.384210.8 0.5852121. 0.8678451.2 1.237921.4 1.674181.6 2.118121.8 2.49172. 2.745012.2 2.8852.4 2.951352.6 2.980072.8 2.991953. 2.996773.2 2.99873.4 2.999483.6 2.999793.8 2.999924. 2.99997

EulerGraph1 = ListPlot[EulerList1]

1 2 3 4

0.5

1.0

1.5

2.0

2.5

3.0

Mathematica for Calculus II Notebook 9_0.nb 11

Page 12: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Show[Field2, EulerGraph1]

0 1 2 3 4

0

1

2

3

4

Clear[x, y]

8. Maclaurin and Taylor series

8.1. Construct the Taylor polynomials of degrees 0 to 4 of a function at x=a and plot them, along with the

original function. We will call the collections of polynomials TaylorTable1.

f[x_] := Exp[x]; a = 2;

T[n_, x_] := SumDerivative[i][f][a] * (x - a)^i Factorial[i], {i, 0, n}

TaylorTable1 = Table[T[n, x], {n, 0, 4}]

ⅇ2, ⅇ2 + ⅇ2 (-2 + x), ⅇ2 + ⅇ2 (-2 + x) +1

2ⅇ2 (-2 + x)2,

ⅇ2 + ⅇ2 (-2 + x) +1

2ⅇ2 (-2 + x)2 +

1

6ⅇ2 (-2 + x)3,

ⅇ2 + ⅇ2 (-2 + x) +1

2ⅇ2 (-2 + x)2 +

1

6ⅇ2 (-2 + x)3 +

1

24ⅇ2 (-2 + x)4

12 Mathematica for Calculus II Notebook 9_0.nb

Page 13: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Plot[{f[x], TaylorTable1}, {x, -1, 4},

PlotStyle → {{Thick, Black}, Red, Orange, Green, Cyan, Blue}]

-1 1 2 3 4

-10

10

20

30

40

50

9. Graphs in polar coordinates

9.1. An 8-petal rose.

PolarPlot[Cos[4 t], {t, 0, 2 * Pi}, PlotStyle → Red]

-1.0 -0.5 0.5 1.0

-1.0

-0.5

0.5

1.0

9.2. The intersection of a circle and a cardiod.

Mathematica for Calculus II Notebook 9_0.nb 13

Page 14: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

PolarPlot[{3 Cos[t], 1 + Cos[t]}, {t, 0, 2 * Pi}, PlotStyle → {Red, Blue}]

0.5 1.0 1.5 2.0 2.5 3.0

-1.5

-1.0

-0.5

0.5

1.0

1.5

10. Vectors

10.1. Addition of vectors.

{1, 2, 3} + {4, 0, -1}

{5, 2, 2}

10.2. Scalar multiplication.

10 {1, 2, 3}

{10, 20, 30}

10.3. Magnitude of a vector.

Norm[{1, 2, 3}]

14

10.4. Dot product.

Dot[{1, 2, 3}, {5, 0, 1}]

8

10.5. Cross product.

Cross[{1, 0, 1}, {0, 1, 0}]

{-1, 0, 1}

11. Graphing lines in 3-dimensional space

11.1. Graph a parametrized line.

14 Mathematica for Calculus II Notebook 9_0.nb

Page 15: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

ParametricPlot3D[{1 + t, 2 t, -1 + t}, {t, 0, 1}]

11.2. Show the graph of a parametrized line within a given size box. Label the axes. Color the line blue.

Mathematica for Calculus II Notebook 9_0.nb 15

Page 16: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

ParametricPlot3D[{1 + t, 2 t, -1 + t}, {t, 0, 1}, PlotRange → {{0, 3}, {0, 5}, {-2, 1}},

AxesLabel → {x, y, z}, PlotStyle → {Thick, Blue}]

11.3. Show a line from a point P=(1,2,3) to a point Q=(4,4,4). Label the points.

Line1 = ParametricPlot3D1 - t * {1, 2, 3} + t * {4, 4, 4}, {t, 0, 1}, PlotRange →

{{0, 5}, {0, 5}, {0, 5}}, AxesLabel → {x, y, z}, PlotStyle → {Thick, Blue};

PLabel = Graphics3D[Text["(1,2,3)", {1.4, 2, 3}]];

QLabel = Graphics3D[Text["(4,4,4)", {4, 4, 4.3}]];

PtGraph1 = ListPointPlot3D[{{1, 2, 3}, {4, 4, 4}}, PlotStyle → PointSize[Large]];

16 Mathematica for Calculus II Notebook 9_0.nb

Page 17: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Show[Line1, PLabel, QLabel, PtGraph1]

12. Graphing planes

12.1. Plot the plane z=x+2y+3 for 0≤x≤3 and 0≤y≤2.

Plot3D[x + 2 y + 3, {x, 0, 3}, {y, 0, 2}, AxesLabel -> {x, y, z}]

12.2. Plot the portion of the plane through the point (1,2,0) with normal vector (2,1,3) such that 0≤x≤4, 0≤

y≤4, and 0≤z≤4.

Mathematica for Calculus II Notebook 9_0.nb 17

Page 18: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

ContourPlot3D2 x - 1 + y - 2 + 3 z ⩵ 0,

{x, 0, 4}, {y, 0, 4}, {z, 0, 4}, AxesLabel -> {x, y, z}

12.3. Plot the triangle determined by the points P=(1,2,3), Q=(4,4,4), and R=(1,3,5). First we find two

vectors in the plane. Then we parametrize the plane in terms of these vectors and the point P as

{x,y,z}={1,2,3}+sv+tw. We take the portion for which 0≤s≤1, 0≤t≤1, and s+t≤1.

v = {4, 4, 4} - {1, 2, 3}

w = {1, 3, 5} - {1, 2, 3}

{3, 2, 1}

{0, 1, 2}

Triangle1 = ParametricPlot3D[{1, 2, 3} + s * v + t * w, {s, 0, 1}, {t, 0, 1},

RegionFunction → Function[{x, y, z, s, t}, s + t < 1], PlotStyle → Blue];

PLabel = Graphics3D[Text["(1,2,3)", {1.4, 2, 3}]];

QLabel = Graphics3D[Text["(4,4,4)", {4, 4, 4.3}]];

RLabel = Graphics3D[Text["(1,3,5)", {1.3, 3, 5.2}]];

PtGraph2 =

ListPointPlot3D[{{1, 2, 3}, {4, 4, 4}, {1, 3, 5}}, PlotStyle → PointSize[Large]];

18 Mathematica for Calculus II Notebook 9_0.nb

Page 19: Mathematica for Calculus II (Version 9.0)...Mathematica for Calculus II (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy December 31, 2013 Contents 1

Show[Triangle1, PLabel, QLabel, RLabel, PtGraph2]

Clear[v, w]

Mathematica for Calculus II Notebook 9_0.nb 19