Quickstart: Mathematica for Calculus I (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy September, 0 Contents. Getting Started. Basic plotting. Solving equations, approximating numerically, and finding roots. Lists and plotting with the Table command 5. Implicit plotting with ContourPlot 6. Defining and evaluating functions 7. Derivatives 8. Combining graphs with the Show command. 9. Symbols and Greek letters 0. The Simplify command. Limits. Integrals. Getting started Open a new Mathematica notebook by selecting File - New - Notebook. You will see a small white tab with a + sign at the top left. Click below and type a command, e.g., the first plot below, then press shiftenter to execute the command. You will see In[]:= appear before your first line of input and Out[]:= before your first output. Click below your output to enter another command. To enter some text, select Format - Style - Text or Alt - 7. To enter Mathematica commands again, click below the text and select Format - Style - Input or Alt-9. To delete a cell or cells, click on the vertical cell markers on the right of the screen and press delete.. Basic plotting.. Plot the graph of sin (x) from x = 0 to x = p. Notice that Plot, Sin, and Pi must all be capitalized. Pay attention to the types of brackets used: [ ] vs { }.
In[]:= Plot@Sin@xD, 8x, 0, * Pi<D Out[]= 5 6 -.. Plot the graphs of the exponential function, the natural logarithm function, and the equation y=x on the same axes from x = - to x=. Note: In Mathematica, the natural logarithm function is Log. We use { } brackets for the list of expressions to be graphed. In[]:= Plot@8Exp@xD, Log@xD, x<, 8x, -, <D 6 Out[]= - - - - -.. Plot Exp[x], Log[x], and x from x=- to x= with the plot range of y restricted to [-,]. Note: The arrow is obtained by typing - and >.
In[]:= Plot@8Exp@xD, Log@xD, x<, 8x, -, <, PlotRange 8-, <D Out[]= - - - - - -.. Plot the tangent and inverse tangent (arctangent) functions from -p/ to p/ with the first plot in red and the second in blue. In[]:= Plot@8Tan@xD, ArcTan@xD<, 8x, - Pi, Pi <, PlotStyle 8Red, Blue<D Out[]= -.5 -.5 - - -.5. Plot the top and bottom halves of the circle x ^ + y =, adjusting the Aspect Ratio to show the same scales on both axes.
In[5]:= Plot@8- Sqrt@ - x ^ D, Sqrt@ - x ^ D<, 8x, -, <, AspectRatio AutomaticD Out[5]= - -. Solving equations, approximating numerically, and finding roots.. Solve the equation x - = 0 for x. Note the double == signs in the Mathematica command. We see that two of the solutions are imaginary. In[6]:= Out[6]= Solve@x ^ - Š 0, xd ::x - >, :x - ä >, :x ä >, :x >>.. Select the th solution from the list of solutions. In[7]:= Out[7]= Solve@x ^ - Š 0, xd@@dd :x >.. Find the real solutions of the equation x -=0. In[8]:= Out[8]= Solve@x ^ - Š 0, x, RealsD ::x - >, :x >>.. Numerically approximate the real solutions of the equation x -=0. In[9]:= Out[9]= NSolve@x ^ - Š 0, x, RealsD 88x -.<, 8x.<<.5. Find a solution of the equation x -=0 in the interval 0<x<.
In[0]:= Out[0]= Solve@x ^ - Š 0 && 0 < x <, xd ::x >>.6. Numerically approximate a root of x -=0 near x=.5. In[]:= Out[]= FindRoot@x ^ -, 8x,.5<D 8x.<.7. Numerically approximate the value of In[]:= Out[]=. N@Sqrt@DD.. Lists with the Table command.. Use Table to make a list of the values of x for integers x from to 5. Note that the output has { } brackets around it, indicating that it has the structure of a list. In[]:= Out[]= Table@x ^, 8x,, 5<D 8,, 9, 6, 5<.. Use Table to make a list of values of x for x in {,,5,7,,,7} and name it PrimeSquares. Note the { } brackets around the list of x values. In[]:= Out[]= PrimeSquares = Table@x ^, 8x, 8,, 5, 7,,, 7<<D 8, 9, 5, 9,, 69, 89<.. Select the 5th element of the list PrimeSquares. In[5]:= Out[5]= PrimeSquares@@5DD.. Construct a list of expressions c*x, for c in the list {-,-,-,,,}, and give it the name LineList. In[6]:= Out[6]= LineList = Table@c * x, 8c, 8-, -, -,,, <<D 8- x, - x, - x, x, x, x<.5. Use Table to plot the lines in the list LineList. 5
6 In[7]:= Plot@LineList, 8x, -, <D Out[7]= - - -.6. Use Table to plot the lines in LineList with the colors orange, yellow, green,cyan,purple,black, and brown. In[8]:= Plot@LineList, 8x, -, <, PlotStyle 8Orange, Yellow, Green, Cyan, Purple, Black, Brown<D Out[8]= - - - 5. Implicit plotting with ContourPlot 5.. Plot the circle x + y = using ContourPlot. Note the double == signs in the command. We must specify the intervals for both x and y.
In[9]:= ContourPlot@x ^ + y ^ Š, 8x, -, <, 8y, -, <D Out[9]= 0.0 - - 0.0 5.. Plot the same circle but with axes and no frame. In[0]:= ContourPlot@x ^ + y ^ Š, 8x, -, <, 8y, -, <, Axes True, Frame FalseD Out[0]= - - 5.. Plot the family of circles x + y = c for c in the list {,,}, x in the interval [-,], and y in the interval [-,], using red, blue, and green. Because of the order in which Mathematica executes commands, we need to tell the program to evaluate the list of equations before plotting with ContourPlot. 7
8 In[]:= Out[]= In[]:= CircleEquations = Table@x ^ + y ^ == c ^, 8c, 8,, <<D 9x + y Š, x + y Š, x + y Š 6= ContourPlot@Evaluate@CircleEquationsD, 8x, - 5, 5<, 8y, - 5, 5<, ContourStyle 8Red, Blue, Green<D Out[]= 0 - - - - 0 6. Defining and evaluating functions In[]:= 6.. Define f HxL = x. f@x_d := x ^ 6.. Evaluate f at x=5 in two different ways. The arrow is obtained by typing - and >. In[]:= Out[]= In[5]:= Out[5]= In[6]:= f@5d 5 f@xd. x 5 5 6.. Define g Hx, yl = x + y. g@x_, y_d := x ^ + y ^ 6.. Evaluate g at x=, y= in two different ways. In[7]:= Out[7]= In[8]:= Out[8]= g@, D 5 g@x, yd. 8x, y < 5
7. Derivatives In[9]:= Out[9]= In[0]:= Out[0]= 7.. Find the derivative of the function f HxL = x defined above. Two methods are shown. D@f@xD, xd x f '@xd x 7.. Evaluate f (5) in two different ways. In[]:= Out[]= In[]:= Out[]= f '@5D 75 D@f@xD, xd. x 5 75 7.. Find the second derivative of f. Two methods are shown. In[]:= Out[]= In[]:= Out[]= f ''@xd 6x D@f@xD, 8x, <D 6x 7.. Find the derivative of x +y with respect to x when y is a function of x. Note that we must specify that y is a function of x by writing y[x]. In[5]:= Out[5]= D@x ^ + y@xd ^, xd x + y@xd y @xd 7.5. Given x +y -5=0, solve for y [x] by implicit differentiation. Give the result the name Slope. In[6]:= Out[6]= Slope = Solve@D@x ^ + y@xd ^ - 5, xd == 0, y '@xdd x ::y @xd >> y@xd 7.6. Find the value of y [x] at x=, y=. Note that we need to type y[x], not just y. In[7]:= Out[7]= Slope. 8x, y@xd < ::y @D - >> 8. Combining graphs with the Show command 8.. Plot the circlex +y -5=0 and its tangent line at (,) on the same axes. Note that we use ; at the end of a command when we do not need to see the result. In[8]:= CircleGraph = ContourPlot@x ^ + y ^ - 5 Š 0, 8x, - 6, 6<, 8y, - 6, 6<, Axes True, Frame FalseD; 9
0 In[9]:= In[0]:= TangentGraph = Plot@- H L * Hx - L +, 8x, - 6, 6<, PlotRange 8-6, 6<, AspectRatio AutomaticD; Show@CircleGraph, TangentGraphD 6 Out[0]= -6 - - 6 - - -6 9. Symbols and Greek letters 9.. The symbol is obtained from esc inf esc. 9.. The symbol ¹ is obtained from esc! = esc. 9.. The symbol is obtained from esc < = esc ( and similarly for ³). 9.. The Greek letter q is obtained from esc theta esc. Other Greek letters are obtained in a similar manner. 9.5. The arrow is obtained by typing - and > or esc -> esc. 0. The Simplify command In[]:= Out[]= 0.. Simplify the expression cos HqL + sin (q). Simplify@Cos@qD ^ + Sin@qD ^ D. Limits.. Find the limit of Exp[-x] as x. In[]:= Out[]= Limit@Exp@- xd, x InfinityD 0.. Find the limit of Log[x] (natural logarithm) as x 0+.
In[]:= Out[]= Limit@Log@xD, x 0, Direction - D -.. Find the limit of /x as x 0-. In[]:= Out[]= Limit@ x, x 0, Direction D -.. Find the limit of Exp[-c*x] as x, with the assumption that c>0. In[5]:= Out[5]= Limit@Exp@- c * xd, x Infinity, Assumptions 8c > 0<D 0.5. Find the limit of ExpA-c *x] as x, with the assumption that c is a real number and c¹0. Note: Type!= or esc!= esc for ¹. In[6]:= Out[6]= Limit@Exp@- c ^ * xd, x Infinity, Assumptions Element@c, RealsD && c ¹ 0D 0. Integrals.. Find the indefinite integral of x. Mathematica does not supply the +C. In[7]:= Integrate@x ^, xd x Out[7]=.. Find the definite integral of x from 0 to. In[8]:= Integrate@x ^, 8x, 0, <D Out[8]=.. Numerically approximate the integral of x from 0 to. In[9]:= Out[9]= NIntegrate@x ^, 8x, 0, <D 0.