(*^
::[ Information =
"This is a Mathematica Notebook file. It contains ASCII text, and can be
transferred by email, ftp, or other text-file transfer utility. It should
be read or edited using a copy of Mathematica or MathReader. If you
received this as email, use your mail application or copy/paste to save
everything from the line containing (*^ down to the line containing ^*)
into a plain text file. On some systems you may have to give the file a
name ending with ".ma" to allow Mathematica to recognize it as a Notebook.
The line below identifies what version of Mathematica created this file,
but it can be opened using any other version as well.";
FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2";
MacintoshStandardFontEncoding;
fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times";
fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times";
fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times";
fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times";
fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times";
fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times";
fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "";
fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times";
fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, 12, "Courier";
fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-4, 12, "Courier";
fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier";
fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier";
fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier";
fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier";
fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Times";
fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "";
fontset = leftheader, inactive, L2, 12, "Times";
fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, 12, "";
fontset = leftfooter, inactive, L2, 12, "Times";
fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times";
fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "";
fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Courier";
fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 14, "Times";
fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "";
fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "";
fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "";
fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "";
paletteColors = 128; automaticGrouping; currentKernel;
]
:[font = title; inactive; preserveAspect; startGroup]
Example 01
Mathematica as a Simple Calculator
;[s]
4:0,0;11,2;22,1;23,0;46,-1;
3:2,25,18,Times,1,24,0,0,0;1,19,14,Times,1,18,0,0,0;1,25,18,Times,3,24,0,0,0;
:[font = subsubtitle; inactive; preserveAspect]
Copyright ã 1993 by Bill Titus, Carleton College,
Department of Physics and Astronomy, Northfield, MN 55057-4025
September 6, 1993
;[s]
3:0,0;10,1;11,0;133,-1;
2:2,16,12,Times,2,14,0,0,0;1,16,12,Symbol,0,14,0,0,0;
:[font = section; inactive; preserveAspect; startGroup]
Topics and Skills
:[font = special1; inactive; preserveAspect; endGroup]
1. Launching MMA.
2. Opening a MMA notebook from within MMA.
3. Brief definition of the kernel and the notebook front end.
4. MMA as a calculator.
5. Simple arithmetic operators.
6. Basic information on input and output cells.
7. Editing contents of cells.
8. Special MMA objects (atomic types).
9. Saving a MMA notebook.
10. Opening a MMA notebook from a file name or icon.
:[font = section; inactive; preserveAspect; startGroup]
Problem
:[font = special1; inactive; preserveAspect]
A ball is thrown vertically upward at 20 m/s from the top of the Olin Hall of Science. What's the ball's velocity and position at the time to = 3.0 s after launch?
:[font = special1; inactive; preserveAspect]
The basic free fall equations, assuming the x-axis points vertically upward and that the origin of the coordinate system is at the launch point, are:
:[font = special1; inactive; preserveAspect; fontSize = 13; fontName = "Courier"]
v[t] = v[0] - gt
x[t] = v[0]t - gt2/2
;[s]
3:0,0;36,1;37,0;40,-1;
2:2,14,10,Courier,0,13,0,0,0;1,22,14,Courier,32,13,0,0,0;
:[font = special1; inactive; preserveAspect; endGroup]
The initial information is then v[0] = 20 m/s, to = 3.0 s, and g = 9.8 m/s2.
;[s]
3:0,0;78,1;79,0;81,-1;
2:2,16,12,Times,0,14,0,0,0;1,24,16,Times,32,14,0,0,0;
:[font = section; inactive; preserveAspect; startGroup]
Solution
:[font = subsection; inactive; preserveAspect]
Step 1 - Launch MMA's front end by double-clicking the MMA icon.
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 1
:[font = special1; inactive; preserveAspect; endGroup]
1. The kernel is the mathematical engine.
2. The notebook front end is for input and output.
:[font = subsection; inactive; preserveAspect]
Step 2 - Use the MMA menu system to located and open the file Ex01.ma
;[s]
2:0,0;62,1;71,-1;
2:1,16,12,Times,1,14,0,0,0;1,15,11,Helvetica,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect]
Step 3 - You'll first use MMA as a calculator and find v[to], assuming all the numbers are integers. Take g = 9 and use * for multiplication and - for subtraction. Move the cursor below this cell. When it becomes a horizontal bar, click the mouse and type in the appropriate numbers. Press to send the results to the kernel.
;[s]
7:0,0;127,1;128,0;154,1;157,0;305,2;312,0;350,-1;
3:4,16,12,Times,1,14,0,0,0;2,15,11,Courier,1,14,0,0,0;1,15,11,Helvetica,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 3
:[font = special1; inactive; preserveAspect; endGroup]
1. The first time you enter any result, it takes what seems like a long time for MMA to respond. Why?
2. To activate a cell, you can use either or .
;[s]
5:0,0;148,1;163,0;168,1;176,0;178,-1;
2:3,16,12,Times,0,14,0,0,0;2,15,11,Helvetica,0,14,0,0,0;
:[font = subsection; inactive; preserveAspect]
Step 4 - Now calculate x[to], again assuming all the number are integers. Use ^ for power and / for division.
;[s]
5:0,0;82,1;83,0;101,1;103,0;119,-1;
2:3,16,12,Times,1,14,0,0,0;2,15,11,Courier,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 4
:[font = special1; inactive; preserveAspect; endGroup]
1. Arithmetic operators: addition, subtraction, multiplication, power, and division.
2. Special objects (atomic types): Integers and Rationals.
3. Input and output cells: the In[] and Out[] notation.
4. Cells: definition, boundaries, brackets, cursor, and creation.
5. Standard use for parentheses to group numbers.
;[s]
5:0,0;183,1;188,0;193,1;198,0;329,-1;
2:3,16,12,Times,0,14,0,0,0;2,15,11,Courier,0,14,0,0,0;
:[font = subsection; inactive; preserveAspect]
Step 5 - In a cell below, repeat the calculations for v[to] and x[to] with reals, now using g = 9.8. Use parentheses to make the order of the evaluation clear.
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 5
:[font = special1; inactive; preserveAspect; endGroup]
1. Atomic type: Real.
2. Real and Integer types can be mixed, but the result is a Real.
:[font = subsection; inactive; preserveAspect]
Step 6 - Copy the last input cell for x[to] to a new cell below by highlighting the old cell's bracket, pressing -c, clicking the cursor below Step 6's cell when you see the cusor become a horizontal bar, and then pressing -v. Now replace the two * with spaces and enter the calculation. Note that your cursor can be anywhere in the input cell when you press . What do you find?
;[s]
9:0,0;118,1;129,0;237,1;248,0;272,2;273,0;387,1;394,0;415,-1;
3:5,16,12,Times,1,14,0,0,0;3,15,11,Helvetica,1,14,0,0,0;1,15,11,Courier,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 6
:[font = special1; inactive; preserveAspect; endGroup]
1. Use standard commands to edit the contents of cells. If you forget what to use, go to MMA's Edit menu.
;[s]
3:0,0;98,1;102,0;110,-1;
2:2,16,12,Times,0,14,0,0,0;1,15,11,Helvetica,0,14,0,0,0;
:[font = subsection; inactive; preserveAspect]
Step 7 - Editing old output. Go back to the previous input, change g to 9.81, and enter the calculation. What do you observe about the reference numbers for In[] and Out[]?
;[s]
5:0,0;164,1;168,0;175,1;180,0;182,-1;
2:3,16,12,Times,1,14,0,0,0;2,15,11,Courier,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 7
:[font = special1; inactive; preserveAspect; endGroup]
1. What's the index order for the In[]'s (input) and Out[]'s (output)?
2. Ways to reference cells:
a. %, %%, %%% ...
b. %n
c. In[n] or Out[n]; n can be negative, so In[-1] is equivalent to %.
;[s]
23:0,0;36,1;40,0;58,1;63,0;113,1;114,0;117,1;119,0;122,1;125,0;126,1;129,0;138,1;140,0;149,1;154,0;160,1;166,0;169,1;170,0;193,1;199,0;221,-1;
2:12,16,12,Times,0,14,0,0,0;11,15,11,Courier,0,14,0,0,0;
:[font = subsection; inactive; preserveAspect]
Step 8 - Check for the presence of the missing input and output cells using some of the cell reference options discussed in Comment 7.
:[font = subsection; inactive; preserveAspect]
Step 9 - You're now going to calculate v[to] and x[to] using reals along with symbols for units. Right after your numbers, type a space and then type in unit(s) using the symbols m for meters and sec for seconds. Use parentheses to make the groupings clear.
;[s]
5:0,0;186,1;188,0;207,1;210,0;272,-1;
2:3,16,12,Times,1,14,0,0,0;2,15,11,Courier,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 9
:[font = special1; inactive; preserveAspect; endGroup]
1. Error message : MMA is warning you that there's a MMA symbol very similar to yours. Error messages are meant to be helpful. Sometimes they are and sometimes they're not.
2. Go back to the last input, stick in an extra left parenthesis somewhere, and enter the results. What happens?
3. Atomic type: Symbol: m, sec
a. MMA defines its own symbols with upper case letters.
b. Start your symbols with lower case letters.
c. Don't start symbols with numbers. What do you think 5sec means?
4. In your calculation, did you really need a space between the number and its symbol?
5. Atomic type: Complex: 5.0 + 6.5I. Complex distinguishes between Integer, Rational, and Real.
6. Atomic type: String: "my string".
;[s]
7:0,0;322,1;323,0;326,1;329,0;508,1;512,0;750,-1;
2:4,16,12,Times,0,14,0,0,0;3,15,11,Courier,0,14,0,0,0;
:[font = subsection; inactive; preserveAspect]
Step 10 - Use Save As in MMA's Notebook menu to save this notebook in your directory under myEx01. Then quit MMA. Look in your directory to see whether the file was indeed saved. What extension to you see on the file?
;[s]
5:0,0;17,1;24,0;94,1;101,0;227,-1;
2:3,16,12,Times,1,14,0,0,0;2,15,11,Helvetica,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 10
:[font = special1; inactive; preserveAspect; endGroup]
1. MMA file extension ma is added to the file under NeXTStep, but not on Macs.
2. Under NeXTStep, there's also a .mb file which contains, among other things, formating information. You can usually eliminate the .mb file without undue harm.
;[s]
7:0,0;23,1;27,0;118,1;121,0;219,1;223,0;249,-1;
2:4,16,12,Times,0,14,0,0,0;3,15,11,Helvetica,0,14,0,0,0;
:[font = subsection; inactive; preserveAspect]
Step 11 - Reload your file myEx01 into MMA by double-clicking on the file's name or its icon.
;[s]
3:0,0;28,1;34,0;98,-1;
2:2,16,12,Times,1,14,0,0,0;1,15,11,Helvetica,1,14,0,0,0;
:[font = subsection; inactive; preserveAspect; startGroup]
Comment 11
:[font = special1; inactive; preserveAspect; endGroup; endGroup]
1. Notice that the In[] and Out[] aren't saved. Why?
;[s]
5:0,0;21,1;25,0;32,1;38,0;60,-1;
2:3,16,12,Times,0,14,0,0,0;2,15,11,Courier,0,14,0,0,0;
:[font = section; inactive; preserveAspect; startGroup]
Practice Problems
:[font = subsection; inactive; preserveAspect]
1. Calculate the area of a circle of radius 2.5 m, keeping the unit for the meter in your calculation.
:[font = subsection; inactive; preserveAspect]
2. Use the unit conversion method to find the number of seconds in a year, starting with 60 sec = 1 min. Use parentheses to make the conversion factors and calculation clear. Type all the input on one line; the input won't wrap around. When you enter the calculation, you may get an error message, depending on what symbols you use for the various units.
:[font = subsection; inactive; preserveAspect]
3. Repeat practice problem 2, but break the line between two parentheses using the return key. What happens when you now enter the calculation? Why? How can you avoid this problem?
:[font = subsection; inactive; preserveAspect; startGroup]
Comment
:[font = special1; inactive; preserveAspect; endGroup]
1. It's ok to break up a command with a provided what's on a single line can't be executed by itself.
;[s]
3:0,0;42,1;50,0;114,-1;
2:2,16,12,Times,0,14,0,0,0;1,15,11,Helvetica,0,14,0,0,0;
:[font = subsection; inactive; preserveAspect; endGroup]
4. Cube the complex number 4 + 5I. Now take its reciprocal. Repeat with the complex number 4 + 5.0I. Why do the results differ?
:[font = section; inactive; preserveAspect; startGroup]
Save Your Notebook
:[font = special1; inactive; preserveAspect; endGroup; endGroup]
In order to conserve on memory space, remove all the output cells from this notebook by highlighting the output cell bracket and pressing -x. Then select Save to store your notebook under the name myEx01.
;[s]
7:0,0;139,1;150,0;166,1;170,0;211,1;217,0;219,-1;
2:4,16,12,Times,0,14,0,0,0;3,15,11,Helvetica,0,14,0,0,0;
^*)