home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Mathematics / Notebooks / CSOMinesCalculus / Tutorial.ma < prev    next >
Text File  |  1992-08-17  |  40KB  |  593 lines

  1. (*^
  2.  
  3. ::[paletteColors = 128; automaticGrouping; currentKernel; 
  4.     fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, L1, e8,  16, "Times"; ;
  5.     fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e6,  18, "Times"; ;
  6.     fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, L1, e6,  14, "Times"; ;
  7.     fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, L1, a20,  16, "Times"; ;
  8.     fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, L1, a15,  14, "Times"; ;
  9.     fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, L1, a12,  14, "Times"; ;
  10.     fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  14, "Times"; ;
  11.     fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  12.     fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, L1,  14, "Courier"; ;
  13.     fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5,  12, "Courier"; ;
  14.     fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  15.     fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  16.     fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  17.     fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, L1,  12, "Courier"; ;
  18.     fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, L1,  10, "Times"; ;
  19.     fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  20.     fontset = Left Header, nohscroll, cellOutline,  12;
  21.     fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, L1,  12;
  22.     fontset = Left Footer, cellOutline, blackBox,  12;
  23.     fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  14, "Times"; ;
  24.     fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  25.     fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12, "Courier"; ;
  26.     fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  27.     fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  28.     fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  29.     fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  30.     fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;]
  31. :[font = title; inactive; preserveAspect; startGroup; ]
  32. A Mathematica Tutorial  
  33. ;[s]
  34. 3:0,0;2,1;13,2;25,-1;
  35. 3:1,14,11,Times,0,16,0,0,0;1,14,11,Times,2,16,0,0,0;1,14,11,Times,0,16,0,0,0;
  36. :[font = subsubtitle; inactive; preserveAspect; ]
  37. for the NeXT computer
  38. :[font = section; inactive; preserveAspect; startGroup; ]
  39. Working with this Tutorial.ma `notebook'
  40. :[font = text; inactive; preserveAspect; ]
  41. Before you can read through this notebook,  you need to know several things about "getting around" inside the notebook window.  This section shows you how to use the mouse to `scroll',  and how to select, change and delete text. 
  42. :[font = subsection; inactive; preserveAspect; startGroup; ]
  43. Learning how to `scroll' through this notebook
  44. :[font = text; inactive; preserveAspect; ]
  45. The mouse is the small rectangular box that is attached to the keyboard.  By sliding the mouse on a smooth surface (such as a  pad), you can control the movement of the cursor on the screen.  You move the cursor to point to items you want to manipulate.   There are two "buttons" on the mouse, either of which will  (unless altered)  work for your purposes.
  46. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  47. Scrolling by using the arrows
  48. :[font = text; inactive; preserveAspect; endGroup; ]
  49. You can use the mouse and the direction arrows at the bottom left of the window to scroll up or down through the tutorial:
  50.    1.  Point the cursor on the `down' arrow that appears at the extreme lower 
  51.          left corner of  this notebook window,
  52.    2.  Click the mouse button once (the text will move up one line in the 
  53.          window);  or simply
  54.    3.  Press (and hold down) the button until the desired amount of new text 
  55.          appears.
  56. You can similarly scroll up,  or backwards,  by using the `up' arrow.
  57. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  58. Scrolling by using the `scroll bar'
  59. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  60.  There is a faster way to move up and down.  Inside the grey margin strip at the left of the window is a short vertical bar with a small circle in the center (the scroll bar).  You can use this bar to scroll quickly down, or up,  the page:
  61.     1.  Point the cursor on the scroll bar, 
  62.     2.  Press the button (hold it down), and 
  63.     3.  Drag the scroll bar down or up to correctly position the text.
  64. :[font = subsection; inactive; preserveAspect; startGroup; ]
  65. More about the mouse and the cursor
  66. :[font = text; inactive; preserveAspect; ]
  67. You will notice that the cursor changes shape as it moves about the screen.  If you move the cursor from a position inside this window to a border of the page, or off the page,  the cursor will change from a vertical I-beam shape to an arrow.   Or,  if you slowly move down the page the cursor will occasionally change, briefly,  to a horizontal I-beam shape.   (This occurs between "cells"s,  where a cell is a block of text defined by the bracket,  ] ,  to the right---e.g. see the  ]  for this paragraph).   Move the cursor around and see it change. 
  68. :[font = text; inactive; preserveAspect; endGroup; ]
  69. The cursor has three basic shapes:
  70.    •  a vertical I-beam, for selecting text in the window; 
  71.    •  a horizontal I-beam, for opening more work space between paragraphs 
  72.        (or cells);
  73.    •  the arrow,  for pointing to items bordering,  or off,  the window.
  74. You will have occasion soon to see the implications of these various shapes.
  75. :[font = subsection; inactive; preserveAspect; startGroup; ]
  76. Adding new text
  77. :[font = text; inactive; preserveAspect; endGroup; ]
  78.  You can change (edit) text by using the mouse.  You can practice adding text right now: 
  79.     1.  Move the cursor to the end of a  nearby paragraph, 
  80.     2.  Click the mouse -- a blinking vertical bar will appear, 
  81.     3.  Add new text there by typing something;  e.g. type:   `Some new stuff' 
  82.           after this sentence.   
  83. :[font = subsection; inactive; preserveAspect; startGroup; ]
  84. Deleting text
  85. :[font = text; inactive; preserveAspect; ]
  86. Here is how to delete the text added above:
  87.    1.  Move the cursor to the beginning of your added text,  just before the "S" 
  88.          in Some , 
  89.    2.  `Select' the text  (i.e.  press and drag the mouse to the right until the  
  90.          `Some new stuff'  is completely shaded in grey), 
  91.    3.  Hit the Delete key (located on the upper right of the main keyboard, with 
  92.          the left arrow).  The shaded text will disappear.
  93. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  94. By combining the above features, moving about, adding and deleting text, one can change the text as desired.   You will get more practice below.
  95. :[font = section; inactive; preserveAspect; startGroup; ]
  96. How to continue this Tutorial---or Quit
  97. :[font = text; inactive; preserveAspect; endGroup; ]
  98. Below you will see seven section titles which serve as a `table of contents' for the rest of this tutorial.  These sections are "closed up" for convenience in finding the section of interest.   For example,  if you needed to get off the computer now,  you would want to "open up" the sections  "How to exit this tutorial"  and  "Logging off the NeXT".   But,  let's assume that you want to open the next section,  "What is Mathematica?"  To do this:
  99.   1.  Put the cursor on the small rectangle to the right of the section title;
  100.   2.  "double-click"---that is,  make two short clicks of the mouse.  
  101.        This  (short) section should open up for you.   Try it.
  102.   
  103. If you want to close up that section,  double-click on the  ]  to the right, enclosing the entire section,  including the title.  Try it.
  104.  
  105. Notice the next section,  "Some basic elements of Mathematica", has a larger rectangle following it;  this is because it is a much larger section. 
  106. Open this section up when you are ready to start learning Mathematica.
  107.  
  108. The last section,  "Some Mathematica commands",  is a summary of the commands that you will be using this year;  and is for later reference.
  109. ;[s]
  110. 9:0,0;423,1;434,2;855,3;866,4;1011,5;1022,6;1051,7;1062,8;1166,-1;
  111. 9:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  112. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  113. What is Mathematica?
  114. ;[s]
  115. 3:0,0;8,1;19,2;20,-1;
  116. 3:1,14,11,Times,1,16,0,0,0;1,14,11,Times,2,16,0,0,0;1,12,9,Times,1,14,0,0,0;
  117. :[font = text; inactive; preserveAspect; endGroup; ]
  118.  Mathematica is a state-of-the-art and remarkably powerful system for doing mathematics by computer.  One can use Mathematica in many different ways, but in your calculus courses you will use only a small portion of its capabilities.   (You will use more advanced features in your later course work and,  very likely,  in your professional career).  The following tutorial sections will show you how to use to do numerical, symbolic and graphical calculations.   You will get a sense of the graphical power in this tutorial.
  119.      One of the remarkable features of Mathematica  is its `symbolic' capabiltity;  i.e.  it ability to very quickly do messy algrebraic computations and simplifications.   Such packages can thus save us many tedious hours of (error-prone) work.   Similarly, you will see later this term that Mathematica is also very good at calculus operations  (differentiation and integration).   
  120. These time saving features will not take all the work out of a calculus course,  rather it will allows us to probe more deeply into central issues of the subject.
  121. ;[s]
  122. 9:0,0;1,1;12,2;114,3;125,4;564,5;575,6;818,7;829,8;1072,-1;
  123. 9:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  124. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  125. Some basic elements of Mathematica
  126. :[font = text; inactive; preserveAspect; ]
  127. In this section we give you examples of how you can use Mathematica for some familiar and elementary operations. 
  128. ;[s]
  129. 4:0,0;56,1;67,2;112,3;113,-1;
  130. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,11,8,Times,0,12,0,0,0;
  131. :[font = subsection; inactive; preserveAspect; startGroup; ]
  132. Executing a Mathematica command
  133. ;[s]
  134. 3:0,0;12,1;23,2;32,-1;
  135. 3:1,12,9,Times,1,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,12,9,Times,1,14,0,0,0;
  136. :[font = text; inactive; preserveAspect; ]
  137. In the first example, we illustrate some of the algebraic and graphical capabilities of Mathematica.   Here is an example of an expression that defines  y, a function of  x:
  138. ;[s]
  139. 4:0,0;88,1;99,2;103,3;173,-1;
  140. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  141. :[font = input; preserveAspect; ]
  142. y = x^3 - x^2 - 9 x + 9
  143. :[font = text; inactive; preserveAspect; ]
  144. The above line is called a command, or "input".  When you enter such an input, Mathematica processes it and returns "output" (or a result). To obtain the result you must first "execute" the command by following these steps:
  145.    1.  Move the cursor to the end of the command;  in this case, after the 
  146.          second  9.   
  147.         (Alternatively,  put the cursor on the  ]  to the right of the command),
  148.    2.  Click the mouse to select the command,
  149.    3.  Hit the Enter key,  located on the extreme lower right of the keyboard.  
  150.         (Note: this is  NOT the same as the Return key that you have been 
  151.          using.)
  152.     
  153. The above command is repeated below.   Follow the directions above to execute it now.  There will be a short delay while Mathematica performs the command. Once the command is completed, you will see an input line labeled  In[1]  that contains the original command, and an output line labeled  Out[1].  Notice that the result in the output line is written differently than the way we typed it;  Mathematica  prefers to write polynomials in increasing powers of  x.
  154. ;[s]
  155. 7:0,0;79,1;90,2;746,3;757,4;1019,5;1032,6;1088,-1;
  156. 7:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  157. :[font = input; preserveAspect; endGroup; ]
  158. y = x^3 - x^2 - 9 x + 9
  159. :[font = subsection; inactive; preserveAspect; startGroup; ]
  160. Writing a Mathematica command
  161. ;[s]
  162. 3:0,0;10,1;21,2;29,-1;
  163. 3:1,12,9,Times,1,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,12,9,Times,1,14,0,0,0;
  164. :[font = text; inactive; preserveAspect; endGroup; ]
  165. The input line above is an example of writing the definition of  y  as the cubic polynomial in  x.  There are two items you should notice in the above command that are peculiar to the  Mathematica  program:
  166.    •  "x cube"and "x square" are typed using the carat (^ ) . 
  167.    •   product  "9 x" does not need a multiplication symbol.  Two possible 
  168.         forms are:   with a space as in "9 x" or  with an asterisk as in "9*x".
  169.  
  170. ;[s]
  171. 7:0,0;185,1;196,2;198,3;206,4;207,5;425,6;428,-1;
  172. 7:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;1,11,8,Times,0,12,0,0,0;
  173. :[font = subsection; inactive; preserveAspect; startGroup; ]
  174. Opening Mathematica work space
  175. ;[s]
  176. 3:0,0;8,1;19,2;31,-1;
  177. 3:1,12,9,Times,1,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,12,9,Times,1,14,0,0,0;
  178. :[font = text; inactive; preserveAspect; ]
  179. Now it's time for you to practice writing a command in Mathematica.  
  180. However, first you must `open' a line to type in as follows:   
  181.    1.  Move the cursor slowly down between two paragraphs  (e.g. between 
  182.          this paragraph and the next one)  until the cursor becomes a  horizontal 
  183.          I-beam.
  184.    2.  Click the mouse;  a grey line will appear across the window. 
  185. ;[s]
  186. 4:0,0;55,1;66,2;70,3;376,-1;
  187. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  188. :[font = text; inactive; preserveAspect; endGroup; ]
  189. For practice, after opening a line,  type the same Mathematica  command that we worked with above, and execute the command.  (Remember:  to execute a command,  first `select' it by clicking behind the command,  and then hit the Enter key.) 
  190. ;[s]
  191. 3:0,0;51,1;64,2;243,-1;
  192. 3:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  193. :[font = subsection; inactive; preserveAspect; startGroup; ]
  194. Plotting a function
  195. :[font = text; inactive; preserveAspect; ]
  196. The command below is a very common plotting format that will soon become familiar to you.  (Note: this plot command assumes the above definition of  y;  if you have not executed a command defining  y,  scroll back and do it now.)
  197. :[font = input; preserveAspect; ]
  198. Plot[y, {x,-7,7}, PlotRange -> All]
  199. :[font = text; inactive; preserveAspect; ]
  200. There are some items to note in this plot command that are peculiar to Mathematica:
  201.    •   Notice the square brackets,  [  and  ],  around the arguments of the Plot 
  202.         command.  Also note {x,-7,7}   specifies the domain of  x.   It is 
  203.         important to remember when to use the different types of brackets.  
  204.         Mathematica is very `narrow minded' about this.
  205.    •  "PlotRange -> All" is a plotting option, telling Mathematica that---"yes, 
  206.         we do want to see the entire graph".  (Other plotting options will be 
  207.         introduced as we need them.)   The arrow (->) is created with the 
  208.         "hyphen" followed by the  "greater than" keys on the keyboard.
  209.    •  Notice the upper case letters in  Plot  and  PlotRange.  This is typical of 
  210.        all Mathematica  functions and options;  so get used to this!  In contrast, 
  211.        if  YOU define a new function, like  y  above,  you are free in the use of 
  212.        upper and lower case letters.
  213. ;[s]
  214. 10:0,0;71,1;82,2;327,3;338,4;430,5;441,6;775,7;786,8;788,9;968,-1;
  215. 10:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  216. :[font = text; inactive; preserveAspect; ]
  217. Execute the plot command below to see what the graph of  y  looks like. (Select the command by clicking after it,  and hit Enter). 
  218. :[font = input; preserveAspect; ]
  219. Plot[y, {x,-7,7}, PlotRange -> All]
  220. :[font = text; inactive; preserveAspect; endGroup; ]
  221. You can see that the graph depicts the essential character of function y.   
  222. :[font = subsection; inactive; preserveAspect; startGroup; ]
  223. Modifying a command
  224. :[font = text; inactive; preserveAspect; ]
  225. You can now practice modifying a Mathematica command and, at the same time, get a closer look at the graph.
  226. ;[s]
  227. 3:0,0;33,1;45,2;107,-1;
  228. 3:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  229. :[font = text; inactive; preserveAspect; ]
  230. Follow these steps to change the domain of  x in the plot command below:
  231.    •  Carefully place the cursor in front of the  -7;
  232.    •  Press and drag the mouse across the -7,7 (it will be shaded grey);
  233.    •  Type  -4,4  (the  -7,7  will be replaced).
  234. Now execute the modified plot command. (If the command does not execute, it's always a good idea to check for typographical errors. If there are no errors  and the graph still does not plot, ask for help.)
  235. :[font = input; preserveAspect; ]
  236. Plot[y, {x,-7,7}, PlotRange -> All]
  237. :[font = text; inactive; preserveAspect; endGroup; ]
  238. You will now see a more detailed graph of y where it crosses the x-axis.
  239. :[font = subsection; inactive; preserveAspect; startGroup; ]
  240. Factoring polynomials
  241. :[font = text; inactive; preserveAspect; ]
  242. In the above graph it looks to the eye as if the function y is equal to 0 somewhere around x = -3,  x = 1, and  x = 3.  How to find where  y=0 is an important question that we will pursue from several directions this semester.   But in this case, the question is easily answered because Mathematica is good at factoring polynomials.   To see this, execute the following command.
  243. ;[s]
  244. 4:0,0;287,1;298,2;299,3;378,-1;
  245. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  246. :[font = input; preserveAspect; startGroup; ]
  247. Factor[y]
  248. :[font = output; output; inactive; preserveAspect; endGroup; ]
  249. (-3 + x)*(-1 + x)*(3 + x)
  250. ;[o]
  251. (-3 + x) (-1 + x) (3 + x)
  252. :[font = text; inactive; preserveAspect; endGroup; ]
  253. It is now clear that y = 0 precisely at  x=-3,  x=1, and  x=3.
  254. :[font = subsection; inactive; preserveAspect; startGroup; ]
  255. Zooming in on a graph
  256. :[font = text; inactive; preserveAspect; ]
  257. Let's return to the graph of y and get into an issue that will be very important throughout our study of calculus.   Again,  execute:
  258. :[font = input; preserveAspect; ]
  259. Plot[y, {x,-4,4}, PlotRange -> All]
  260. :[font = text; inactive; preserveAspect; ]
  261. A recuring theme in calculus can be paraphrased:  "most functions are `almost linear' if you look closely enough".  To illustrate this point, you can "zoom" in on the graph at  x  near  2: 
  262.     1.  Modify the plot command below so that the domain of x is 1.9  to  2.1.   
  263.          (If  necessary, you may scroll back to review the directions  "Modifying 
  264.          a  command.")
  265.     2.  Execute the plot command.
  266. :[font = text; inactive; preserveAspect; ]
  267. You should see a smaller section of the graph and note that it is starting to straighten out a bit.  To further illustrate the point,  modify the x domain in the plot command below to 1.99 to 2.01 and execute the command, and notice that the graph is almost linear. 
  268. :[font = input; preserveAspect; ]
  269. Plot[y, {x, 1.99, 2.01}, PlotRange -> All]
  270. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  271. Is there anything special about the point  (2, -5)?  No.   You may want to experiment on your own by modifying the command with any value for the domain of  x that you choose, and "zoom in" as we have done.  Remember the fundamental point being made:
  272.      "most functions are `almost linear' if you look closely enough".
  273. We will revisit this notion often in Calculus.
  274. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  275. Some additional issues
  276. :[font = text; inactive; preserveAspect; ]
  277. Below we point out a few more characteristics in some  Mathematica  commands that you will use during the year.  Execute each command, notice its output, and read the explanation that follows.
  278. ;[s]
  279. 4:0,0;55,1;66,2;68,3;192,-1;
  280. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  281. :[font = input; preserveAspect; ]
  282. y
  283. :[font = text; inactive; preserveAspect; ]
  284. Here we have defined y as we had earlier.   Now consider
  285. :[font = input; preserveAspect; ]
  286. xy
  287. :[font = text; inactive; preserveAspect; ]
  288.  Mathematica considers  xy as a new variable, since we `forgot' the space between  x  and  y.   Now execute:
  289. ;[s]
  290. 4:0,0;1,1;12,2;13,3;108,-1;
  291. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  292. :[font = input; preserveAspect; ]
  293. x y 
  294. :[font = text; inactive; preserveAspect; ]
  295. Mathematica  remembers the definition of  y  and substitutes it in. 
  296. ;[s]
  297. 2:0,0;11,1;69,-1;
  298. 2:1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  299. :[font = input; preserveAspect; ]
  300. Expand[%]
  301. :[font = text; inactive; preserveAspect; ]
  302. In this  Expand  command, the percent sign (%) stands for  `the last result'.  Therefore, the product x y  is expanded here to get a fourth degree polynomial.
  303. :[font = input; preserveAspect; ]
  304. Factor[%]
  305. :[font = text; inactive; preserveAspect; ]
  306. Likewise,  this factors the last result.   Finally, a bit more subtle command:
  307. :[font = input; preserveAspect; ]
  308. y /. x -> 2
  309. :[font = text; inactive; preserveAspect; ]
  310. The effect of this command is to evaluate  y  at  x=2.  It illustrates a very important feature of  Mathematica.   You should read this command as "evaluate  y  subject to the rule:  (x  is set to 2)".  The operator  /.  is made up by a slash  /  followed by a period  (.);  and the arrow is a "hyphen" followed by a "greater than"  sign.   The spaces after the  y, before the  x  and before the  2  are NOT necessary here, but they help in the readability of the command.
  311. ;[s]
  312. 3:0,0;100,1;115,2;472,-1;
  313. 3:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  314. :[font = subsection; inactive; preserveAspect; startGroup; ]
  315. The "Function" Notation
  316. :[font = text; inactive; preserveAspect; ]
  317. As you probably noticed, the last example is an awkward way to evaluate  y  at  x = 2.  An easier way to do such evaluations it is to use the "function" notation.  The following is an example of a function definition for  f :
  318. :[font = input; preserveAspect; ]
  319. f[x_] := x^2 + 1
  320. :[font = text; inactive; preserveAspect; endGroup; ]
  321. There are several items to note in the above command that are peculiar to  Mathematica  and that you must include to make  f  a legitimate function:  
  322.     •  square brackets must be used to enclose the argument of  f,
  323.     •  an underscore (shift on the hyphen) follows the argument inside the 
  324.         brackets, and
  325.     •  the assignment operator  :=  replaces the usual equal sign.   
  326. ;[s]
  327. 3:0,0;75,1;88,2;386,-1;
  328. 3:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  329. :[font = subsection; inactive; preserveAspect; startGroup; ]
  330. Examples using a defined function
  331. :[font = text; inactive; preserveAspect; ]
  332. Some advantages of the function notation are shown in the  examples below.  These examples give you an idea of the power you have in Mathematica  when  f  is defined as an actual function. The original argument,  x, can be replaced by any numerical value or symbol.   EXECUTE the following commands, one at a time, starting with the definition of  f .
  333. ;[s]
  334. 4:0,0;133,1;144,2;146,3;351,-1;
  335. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  336. :[font = input; preserveAspect; ]
  337. f[x_] := x^2 + 1
  338. :[font = input; preserveAspect; ]
  339. f[x]
  340. :[font = input; preserveAspect; ]
  341. f[3]
  342. :[font = input; preserveAspect; ]
  343. f[-3]
  344. :[font = input; preserveAspect; ]
  345. f[-12]
  346. :[font = input; preserveAspect; ]
  347. f[p]
  348. :[font = input; preserveAspect; ]
  349. f[cat]
  350. :[font = input; preserveAspect; ]
  351. f[t^3+1]
  352. :[font = input; preserveAspect; ]
  353. Expand[%]
  354. :[font = text; inactive; preserveAspect; endGroup; ]
  355. As you can see, the original argument,  x, can be replaced by ANYTHING!  For example, with the argument  t^3 + 1  we obtained a sixth degree polynomial (the `composition' of the functions  x^2 + 5 and t^3 + 1).  
  356. :[font = subsection; inactive; preserveAspect; startGroup; ]
  357. Working with a Rational Function
  358. :[font = text; inactive; preserveAspect; ]
  359. You can form a so-called "rational function" by taking the quotient of y and f[x].   Execute the following command to define the ratio of  y and  f[x], and then execute the second command to plot the function.
  360. :[font = input; preserveAspect; ]
  361. r = y/f[x]
  362. :[font = input; preserveAspect; ]
  363. Plot[r, {x, -20, 20}, PlotRange -> All]
  364. :[font = text; inactive; preserveAspect; ]
  365. You can see here that  r  has the same general shape,  for "small" x, as did  y.  (Why is this?)  Also notice that for "large x" the graph of  r  looks linear.  (Why is this?)  To explore the second question graphically we plot functions  r and  x-1  on the same graph as follows.  Execute the command:
  366. :[font = input; preserveAspect; ]
  367. Plot[{r, x-1}, {x, -40, 40}, PlotRange -> All]
  368. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  369. In this tutorial, you have seen demonstrated two phenomena that are quite common:
  370.     1.  Most functions look linear if you zoom in very close; that is, if you look 
  371.           at the function over a very small interval.
  372.     2.  Some (but not most) functions look linear if you look at them from a 
  373.           large distance.  
  374. The concepts of "very close" and "very far" play central roles in calculus, as you will see this semester.
  375. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  376. Now you try some things
  377. :[font = text; inactive; preserveAspect; ]
  378. With the information given above on how to write and execute Mathematica commands, you can now experiment on your own with the Mathematica concepts demonstrated in this tutorial. You may either use the exercises given below, or try some functions of your own choice.  If you need to review some information in the previous sections, just scroll up to the appropriate location  (or refer to your booklet).  Remember, in order to open space to work in after each exercise, you must:
  379.    •  place the cursor between two cells (get the horizontal cursor),
  380.    •  click the mouse (a grey line will appear across the window), and 
  381.    •  begin typing the Mathematica command.
  382. ;[s]
  383. 7:0,0;61,1;72,2;127,3;138,4;646,5;657,6;667,-1;
  384. 7:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;
  385. :[font = text; inactive; preserveAspect; ]
  386. If you do not have time to complete the exercises now and if you wish to exit this tutorial, scroll down to the section describing how to do this.
  387. :[font = subsection; inactive; preserveAspect; startGroup; ]
  388. Exercises:
  389. :[font = text; inactive; preserveAspect; ]
  390. 1.   Define function  y = x^3 + 2 x^2 - 15 x - 30.   Plot  y  on several
  391.       x-intervals to get a good idea of its behavior.    
  392. :[font = text; inactive; preserveAspect; ]
  393. 2.  Zoom in on the the largest x-value for which  y = 0.  Does the function 
  394.       become "almost linear" as you zoom in?    
  395. :[font = text; inactive; preserveAspect; ]
  396. 3.  Use the  /.  Mathematica operator to evaluate  y  at several  x  values.
  397. :[font = text; inactive; preserveAspect; ]
  398. 4.  Define a new rational function, e.g.  r = y/(x^4 + 3).   Plot  r  on several  
  399.       x-intervals;  for example look for values of  x  such that  r = 0; and see 
  400.       what  r looks like for  x  "large".   Is  r  "almost linear" for  x  large (as 
  401.       was the case with our  r  discussed earlier)?
  402. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  403. 5.  Use the Factor command to find exactly the x-values where  y  and  r = 0.
  404. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  405. How to exit this tutorial
  406. :[font = text; inactive; preserveAspect; endGroup; ]
  407. To exit this tutorial, you move the cursor to the Mathematica menu located at the extreme upper left corner of your screen.  Point the cursor and click on the "Quit" rectangle at the bottom of the  menu .   You will be presented with a  "Quit"  box with some options; click the  "Quit Anyway"  box. 
  408. ;[s]
  409. 3:0,0;50,1;62,2;299,-1;
  410. 3:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  411. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  412. Logging off the NeXT
  413. :[font = text; inactive; preserveAspect; endGroup; ]
  414. Once you have left the tutorial, to log off the computer move the cursor to the  "Log Out" box of the Workspace Menu (upper left of the screen)  and click there.  Then on the Quit menu box, click on  Log Out.
  415. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  416.  Some Mathematica commands
  417. ;[s]
  418. 3:0,0;6,1;17,2;26,-1;
  419. 3:1,14,11,Times,1,16,0,0,0;1,14,11,Times,2,16,0,0,0;1,14,11,Times,1,16,0,0,0;
  420. :[font = subsection; inactive; preserveAspect; startGroup; ]
  421. Introduction
  422. :[font = help; inactive; preserveAspect; ]
  423. Below we give a list of Mathematica  commands that you will use this year.   But first,  recall that there are two basic ways to define a function of  x.   The quick way is, for example:
  424. ;[s]
  425. 4:0,0;24,1;35,2;37,3;186,-1;
  426. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  427. :[font = input; preserveAspect; ]
  428. y = 3 x + 1
  429. :[font = help; inactive; preserveAspect; ]
  430. The lengthier way, but which allows more flexibility, is:
  431. :[font = input; preserveAspect; ]
  432. f[x_] := x^3 + x^2 - 5x - 5
  433. :[font = help; inactive; preserveAspect; ]
  434. Note:  both the x _  symbol on the left,  and the  :=  defining symbol.   Defining  f  this way allows you to easily evaluate, say,  f[2] ,  f[5 t + 3], etc.  In contrast,  to evaluate the above   y  at  x = 2   you must type:
  435.  
  436. :[font = input; preserveAspect; ]
  437. y /. x -> 2
  438. :[font = help; inactive; preserveAspect; ]
  439. Remember that Mathematica tends to do exact arithmetic;  for example, carrying the fraction  2358463 / 78932749.   This is time-consuming for the computer and one usually prefers the decimal approximation.   One way  to get the decimal form is to use the  N  command; e.g. 
  440. ;[s]
  441. 4:0,0;14,1;25,2;26,3;273,-1;
  442. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  443. :[font = input; preserveAspect; ]
  444. N[2358463/78932749]
  445. :[font = help; inactive; preserveAspect; ]
  446. Or, you can simply put a decimal point after one of the integers.  Try it. 
  447. If you really need lots of decimal places of p you can type, e.g.:
  448. ;[s]
  449. 3:0,0;121,1;122,2;142,-1;
  450. 3:1,13,10,Times,0,14,0,0,0;1,0,0,Symbol,0,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  451. :[font = input; preserveAspect; endGroup; ]
  452. goodPi = N[Pi, 50]
  453. :[font = subsection; inactive; preserveAspect; startGroup; ]
  454. Getting Help during a  Mathematica  session
  455. ;[s]
  456. 3:0,0;23,1;34,2;51,-1;
  457. 3:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  458. :[font = help; inactive; preserveAspect; ]
  459. Suppose that you have used a command before, but have forgotten its exact format.  You can simple type,  for example:
  460.  
  461. :[font = input; preserveAspect; ]
  462. ?Plot
  463. :[font = help; inactive; preserveAspect; endGroup; ]
  464. Or if you want more detail, type   ??Plot .   Try it.
  465.  
  466. :[font = subsection; inactive; preserveAspect; startGroup; ]
  467. A Warning about variable names
  468. :[font = help; inactive; preserveAspect; endGroup; ]
  469. Should you have another Mathematica notebook open  (e.g.,  Project1.ma), the two notebooks will share the same variables.   For example, suppose in another notebook you had defined a variable  y  differently that we have above.  Then you come to this notebook and execute the above  y  definition.   When you return to the other notebook  y  would be changed to the above.        
  470.       However,  if you simply call in this notebook to refresh your memory on a command, and do no execution,  there is no problem.   
  471. ;[s]
  472. 4:0,0;24,1;35,2;36,3;515,-1;
  473. 4:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,11,8,Times,0,12,0,0,0;1,13,10,Times,0,14,0,0,0;
  474. :[font = subsection; inactive; preserveAspect; startGroup; ]
  475. A Partial List of  Mathematica Commands.
  476. ;[s]
  477. 3:0,0;19,1;30,2;40,-1;
  478. 3:1,13,10,Times,0,14,0,0,0;1,13,10,Times,2,14,0,0,0;1,13,10,Times,0,14,0,0,0;
  479. :[font = help; inactive; preserveAspect; ]
  480. The  following commands are in alphabetical order.  If the command is on a separate line, as in the example for  D  below, you can execute it if you wish; ASSUMING the above  y  and  f[x]  have been executed.
  481.  
  482. :[font = subsubsection; inactive; preserveAspect; fontLeading = 9; startGroup; ]
  483. Abs---take the absolute value of its argument; e.g.
  484. :[font = input; preserveAspect; endGroup; ]
  485. Abs[f[2]]
  486. :[font = subsubsection; inactive; preserveAspect; ]
  487. Clear---is used to "undefine" variables or functions.  This is useful when you are changing the definition of f,  or things have gotten confused.  For example, Clear[f,  y] clears above functions.
  488. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  489. D---will take the derivative of specified function with respect to specfied variable.  E.g.,  
  490. :[font = input; preserveAspect; endGroup; ]
  491. D[f[x], x]
  492. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  493. Do---allows you to set up a "loop" in order to perform the same (or similar) commands numerous times.  E.g.,  the following does 6 Newton iterations on function  t^2 - 5,  to approximate  Sqrt[5]:
  494. :[font = input; preserveAspect; ]
  495. t = 3.0
  496. Do[t = t - (t^2 - 5.0) / (2.0 t), {k, 1, 6}]
  497. t
  498. :[font = help; inactive; preserveAspect; endGroup; ]
  499. The variable  k  is a `counter' that here takes on values 1,2,3,4,5,6.
  500. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  501. Expand---expands out in powers of x (or some other expression).
  502. E.g., consider these two examples:
  503. :[font = input; preserveAspect; ]
  504. Expand[y f[x]]
  505. :[font = input; preserveAspect; endGroup; ]
  506. Expand[Cos[x] (3 - Cos[x]^2)]
  507. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  508. Integrate---the first form of  Integrate  attempts to find an antiderivative of the first argument, with respect to the second.  
  509. :[font = input; preserveAspect; ]
  510. Integrate[y, x]
  511. :[font = help; inactive; preserveAspect; ]
  512. The second form is for doing a definite integral;  e.g. 
  513. :[font = input; preserveAspect; ]
  514. Integrate[y, {x, 0, 3}]
  515. :[font = help; inactive; preserveAspect; endGroup; ]
  516. (Should this fail,  see  NIntegrate  below).
  517. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  518. Factor---will attempt to factor the argument.  In polynomials, it only looks for  integer factors.  E.g.,
  519. :[font = input; preserveAspect; endGroup; ]
  520. Factor[f[x]]
  521. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  522. Limit---will attempt to take the specified limit.  
  523. :[font = input; preserveAspect; ]
  524. Limit[y, x -> 3]
  525. :[font = text; inactive; preserveAspect; ]
  526. The following takes the limit from the right  (use  +1  to get the limit from the left):
  527. :[font = input; preserveAspect; endGroup; ]
  528. Limit[f[x], x -> 0, Direction -> -1]
  529. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  530. N---converts the argument to decimal form and shows  6  figures.   More figures are shown if requested;  e.g.,
  531. :[font = input; preserveAspect; ]
  532. N[Pi]
  533. :[font = input; preserveAspect; endGroup; ]
  534. N[Pi/2, 16]
  535. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  536. NIntegrate---attempts to do a numerical integration of the first argument.   Typically, the result is good to 16 figures.  E.g.,
  537. :[font = input; preserveAspect; ]
  538. NIntegrate[y, {x, 0, 3}]
  539. :[font = help; inactive; preserveAspect; endGroup; ]
  540. (Also see Integrate  above).
  541. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  542. Plot---plots one or more functions over the specified interval.  There are many options (try ??Plot), the most common is perhaps PlotRange.  E.g.  try this with,  and without,  the option:
  543. :[font = input; preserveAspect; ]
  544. Plot[{y, f[x]}, {x,-4,4}, PlotRange -> All]
  545.  
  546. :[font = help; inactive; preserveAspect; ]
  547. To get a label on a plot we can do e.g.:
  548. :[font = input; preserveAspect; ]
  549. Plot[{y, f[x]}, {x,-4,4}, PlotRange -> All,
  550.       PlotLabel -> "J. Jacobs Project No. 6"]
  551. :[font = help; inactive; preserveAspect; endGroup; ]
  552. where a `Return' (not `Enter') was used to go to a new line.
  553. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  554. Sign---produces the  sign  (+1  or  -1)  of the argument;  e.g.
  555. :[font = input; preserveAspect; ]
  556. Sign[-Pi/2]
  557. :[font = help; inactive; preserveAspect; ]
  558. This function is useful in producing "step functions";  e.g.,   
  559. :[font = input; preserveAspect; endGroup; ]
  560. g[x_] := Sign[x - 1] - Sign[x - 3]
  561. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  562. Simplify---attempts to clean up the expression by looking for common factors, etc.  E.g., 
  563. :[font = input; preserveAspect; endGroup; ]
  564. Simplify[(f[x]- y) / (x + 3)]
  565. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  566. Solve---attempts to solve the specified equation (or equations) for the specified variables.  Solve is effective primarily for polyomial equations.  E.g. this finds x-values at which f[x] and y are equal:
  567. :[font = input; preserveAspect; ]
  568. ourRules = Solve[y == f[x], x]
  569. :[font = help; inactive; preserveAspect; ]
  570. The result of this is a set of "rules", saved in a variable we called `ourRules', which can be used as follows to evaluate y at these x values:
  571. :[font = input; preserveAspect; ]
  572. y /. ourRules
  573. :[font = help; inactive; preserveAspect; ]
  574. Next we solve a pair of equations for unknown s, t:
  575. :[font = input; preserveAspect; endGroup; ]
  576. Solve[{3 s + t == 7,  2 s - 3 t == 1}, {s,t}]
  577. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  578. Sum---this command allows you to conveniently perform a  sum,  as a `counter ' (k  below) takes on its range of values.   E.g.  to compute the sum of squares of the first six integers: 
  579. :[font = input; preserveAspect; endGroup; ]
  580. sumsq = Sum[k^2, {k, 1, 6}]
  581. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  582. Table and TableForm---Table is used, for example, to generate a list of order pairs; and
  583. TableForm puts them in a more readable form;  e.g.
  584. :[font = input; preserveAspect; endGroup; ]
  585. Table[{n, n^2}, {n, 1, 5}] //TableForm
  586. :[font = subsubsection; inactive; preserveAspect; startGroup; ]
  587. Together---puts terms in a sum over a common denominator, and does some simplifying.   E.g.,
  588. :[font = input; preserveAspect; ]
  589.  (1 + x) y + f[x] / (1 - x)
  590.  
  591. :[font = input; preserveAspect; endGroup; endGroup; endGroup; endGroup; ]
  592. Together[%]
  593. ^*)