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. 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, derivatives, 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. 2 Mathematica for Calculus II Notebook 9_0.nb RevolutionPlot3DExp x, x, 0, 1 2.2. Plot the surface generated by revolving the graph of sin (x) from x = 0 to x = p around the x-axis. N Note: The arrow is Ø obtained by typing - and >. RevolutionPlot3DSinx, 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=x 4 around the x-axis. Show with the same scale on both axes. Color the top surface green and the bottom surface blue. Mathematica for Calculus II Notebook 9_0.nb RevolutionPlot3DSqrtx, 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. 3 4 Mathematica for Calculus II Notebook 9_0.nb RevolutionPlot3DSqrtx, 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. Mathematica for Calculus II Notebook 9_0.nb RevolutionPlot3DSqrtx, 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. Cleara, b, c, d Solvea 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 a , b 3 , a , b 3 , a 3 , a , b 2 , b 0, a 3 , 2 , b 0 3.3. Find the real solutions of a system of nonlinear equations. 5 6 Mathematica for Calculus II Notebook 9_0.nb 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 1 2 x 4 x2 x 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”. VectorPlot1, 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 Mathematica for Calculus II Notebook 9_0.nb 7 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" 4 3 2 1 0 0 1 2 3 4 6. Solutions of differential equations 6.1. Solve a differential equation exactly. C[1] represents an unknown constant. DSolvey 'x x yx, yx, x yx x2 2 C1 , yx x2 2 C1 6.2. Solve a differential equation with initial condition. DSolvey 'x x yx, y0 2, yx, x DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution. à yx 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]. 8 Mathematica for Calculus II Notebook 9_0.nb Solution1 DSolvey 'x yx 3 yx, y0 0.1, yx, x; Plotyx . 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. à 3.0 2.5 2.0 1.5 1.0 0.5 1 2 3 4 6.4. Solve the same differential equation numerically and plot it. Solution2 NDSolvey 'x yx 3 yx, y0 0.1, y, x, 0, 4; Plotyx . Solution2, x, 0, 4 3.0 2.5 2.0 1.5 1.0 0.5 1 2 3 4 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 Tablec3 c, c, 0, 0.1, 1, 2, 3, 4; Solution3 DSolvey 'x yx 3 yx, y0 c3, yx, x; Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. à Solutionlist3 yx . 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 Mathematica for Calculus II Notebook 9_0.nb 9 PlotSolutionlist3, x, 0, 4 4 3 2 1 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 yx 3 yx, y0 c4, y, x, 0, 4, c4, c4list; SolutionPlot4 Plotyx . Solutions4, x, 0, 4, PlotStyle Thick 4 3 2 1 1 2 3 4 6.7. We combine the direction field from 5.2 with the solution plot above. 10 Mathematica for Calculus II Notebook 9_0.nb ShowField2, SolutionPlot4 4 3 2 1 0 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. Clearx, y; x0 0; y0 0.1; h 0.2; yi_ : yi yi 1 h yi 1 3 yi 1 xi_ : xi xi 1 h EulerList1 Tablexi, yi, i, 0, 20; Mathematica for Calculus II Notebook 9_0.nb TableFormEulerList1, TableHeadings None, "x", "y" x 0 0.2 0.4 0.6 0.8 1. 1.2 1.4 1.6 1.8 2. 2.2 2.4 2.6 2.8 3. 3.2 3.4 3.6 3.8 4. y 0.1 0.158 0.247807 0.38421 0.585212 0.867845 1.23792 1.67418 2.11812 2.4917 2.74501 2.885 2.95135 2.98007 2.99195 2.99677 2.9987 2.99948 2.99979 2.99992 2.99997 EulerGraph1 ListPlotEulerList1 3.0 2.5 2.0 1.5 1.0 0.5 1 2 3 4 11 12 Mathematica for Calculus II Notebook 9_0.nb ShowField2, EulerGraph1 4 3 2 1 0 0 1 2 3 4 Clearx, 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. fx_ : Expx; a 2; Tn_, x_ : SumDerivativeifa x a ^ i Factoriali, i, 0, n TaylorTable1 TableTn, x, n, 0, 4 2 , 2 2 2 x, 2 2 2 x 2 2 2 x 2 2 2 x 1 2 1 2 2 2 x2 2 2 x2 1 6 1 6 1 2 2 2 x2 , 2 2 x3 , 2 2 x3 1 24 2 2 x4 Mathematica for Calculus II Notebook 9_0.nb Plotfx, TaylorTable1, x, 1, 4, PlotStyle Thick, Black, Red, Orange, Green, Cyan, Blue 50 40 30 20 10 -1 1 2 3 4 -10 9. Graphs in polar coordinates 9.1. An 8-petal rose. PolarPlotCos4 t, t, 0, 2 Pi, PlotStyle Red 1.0 0.5 -1.0 -0.5 0.5 -0.5 -1.0 9.2. The intersection of a circle and a cardiod. 1.0 13 14 Mathematica for Calculus II Notebook 9_0.nb PolarPlot3 Cost, 1 Cost, t, 0, 2 Pi, PlotStyle Red, Blue 1.5 1.0 0.5 0.5 1.0 1.5 2.0 2.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. Norm1, 2, 3 14 10.4. Dot product. Dot1, 2, 3, 5, 0, 1 8 10.5. Cross product. Cross1, 0, 1, 0, 1, 0 1, 0, 1 11. Graphing lines in 3-dimensional space 11.1. Graph a parametrized line. 3.0 Mathematica for Calculus II Notebook 9_0.nb ParametricPlot3D1 t, 2 t, 1 t, t, 0, 1 2.0 1.5 1.0 0.5 0.0 0.0 -0.5 -1.0 1.0 1.5 2.0 11.2. Show the graph of a parametrized line within a given size box. Label the axes. Color the line blue. 15 16 Mathematica for Calculus II Notebook 9_0.nb ParametricPlot3D1 t, 2 t, 1 t, t, 0, 1, PlotRange 0, 3, 0, 5, 2, 1, AxesLabel x, y, z, PlotStyle Thick, Blue 4 y 2 10 0 z -1 -2 0 1 x 2 3 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 Graphics3DText"1,2,3", 1.4, 2, 3; QLabel Graphics3DText"4,4,4", 4, 4, 4.3; PtGraph1 ListPointPlot3D1, 2, 3, 4, 4, 4, PlotStyle PointSizeLarge; Mathematica for Calculus II Notebook 9_0.nb 17 ShowLine1, PLabel, QLabel, PtGraph1 4 y 2 4,4,4 0 1,2,3 4 z 2 0 0 2 x 4 12. Graphing planes 12.1. Plot the plane z=x+2y+3 for 0§x§3 and 0§y§2. Plot3Dx 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. 18 Mathematica for Calculus II Notebook 9_0.nb 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 ParametricPlot3D1, 2, 3 s v t w, s, 0, 1, t, 0, 1, RegionFunction Functionx, y, z, s, t, s t 1, PlotStyle Blue; PLabel Graphics3DText"1,2,3", 1.4, 2, 3; QLabel Graphics3DText"4,4,4", 4, 4, 4.3; RLabel Graphics3DText"1,3,5", 1.3, 3, 5.2; PtGraph2 ListPointPlot3D1, 2, 3, 4, 4, 4, 1, 3, 5, PlotStyle PointSizeLarge; Mathematica for Calculus II Notebook 9_0.nb ShowTriangle1, PLabel, QLabel, RLabel, PtGraph2 Clearv, w 19