(************** Content-type: application/mathematica **************
CreatedBy='Mathematica 5.0'
Mathematica-Compatible Notebook
This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.
To get the notebook into a Mathematica-compatible application, do
one of the following:
* Save the data starting with the line of stars above into a file
with a name ending in .nb, then open the file inside the
application;
* Copy the data starting with the line of stars above to the
clipboard, then use the Paste menu command inside the application.
Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode. Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).
NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.
For more information on notebooks and Mathematica-compatible
applications, contact Wolfram Research:
web: http://www.wolfram.com
email: info@wolfram.com
phone: +1-217-398-0700 (U.S.)
Notebook reader applications are available free of charge from
Wolfram Research.
*******************************************************************)
(*CacheID: 232*)
(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[ 17264, 579]*)
(*NotebookOutlinePosition[ 17994, 604]*)
(* CellTagsIndexPosition[ 17950, 600]*)
(*WindowFrame->Normal*)
Notebook[{
Cell[TextData[StyleBox["Worksheet 0: The basics",
FontSize->13]], "Text",
FontWeight->"Bold"],
Cell["\<\
[Name]
[Date]
[Section]\
\>", "Text"],
Cell[TextData[{
"\nWelcome to ",
StyleBox["PHY 102: ",
FontWeight->"Bold"],
StyleBox["Mathematica. ",
FontWeight->"Bold",
FontSlant->"Italic"],
StyleBox[" ",
FontSlant->"Italic"],
"The goal of this class is to teach you ",
StyleBox["Mathematica ",
FontSlant->"Italic"],
"so you can use it later on in your physics career (*it comes in handy). \
You will be assigned weekly worksheets to be handed in by each Thursday. The \
assignments are required work, but additional ",
StyleBox["Mathematica",
FontSlant->"Italic"],
StyleBox[" ",
FontWeight->"Bold",
FontSlant->"Italic"],
"work is encouraged. ",
StyleBox["\n\n",
FontWeight->"Bold",
FontSlant->"Italic"],
"We'll begin with a description of some ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" fundamentals and illustrate them with examples. Don't worry too much \
about the details of these examples - they are just to give you an idea of \
the syntax of the language. We'll get into the details later on.\n\nYou are \
encouraged to evaluate and experiment with the examples in this worksheet. \
The goal of this is to give you a basic idea of ",
StyleBox["Mathematica",
FontSlant->"Italic"],
",",
StyleBox[" ",
FontWeight->"Bold"],
"so feel free to explore.",
StyleBox["\n",
FontWeight->"Bold"],
" "
}], "Text"],
Cell[CellGroupData[{
Cell[TextData[{
StyleBox["Cell Brackets",
FontSize->14,
FontWeight->"Bold"],
StyleBox["\nMathematica",
FontSlant->"Italic"],
" ",
StyleBox[" ",
FontWeight->"Bold",
FontSlant->"Italic"],
"is unlike many other programming languages in that the commands may be \
separately run, as opposed to running the entire program all at once. ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" accomplishes this by using brakets to group commands. Note the blue \
bracket to the right of this text. These blue brackets designate cell \
groups. When a command is executed, all commands within the given cell group \
are processed. This allows you to examine the results of one set of \
computations before proceeding onto the next set.\.18"
}], "Text"],
Cell[TextData[{
"Example: ",
StyleBox[" Evaluate the commands in the next bracket. Do this by moving \
the cursor down to the next bracket and pressing [shift]+[enter] to evaluate \
its commands.",
FontWeight->"Plain"]
}], "Text",
FontWeight->"Bold"],
Cell[BoxData[{
\(8/\((2 + 3)\)\), "\[IndentingNewLine]",
\({x0, y0}\ = {5, \ 10}\), "\[IndentingNewLine]",
\(MatrixForm[{{2, 3, 4}, {6, 3, 6}, {2, 4, 1}}]\)}], "Input"],
Cell["\<\
Note that the second command prints to the screen, even though we \
are just assigning values to x0 and y0. Generally, assignments such as these \
are not intended to produce output. This output can be \"silenced\" by \
adding a semicolon at the end of the line. Try evaluating: \
\>", "Text"],
Cell[BoxData[
\(\({x0, y0} = {5, 10};\)\)], "Input"],
Cell[TextData[{
StyleBox["Creating Cells. ",
FontWeight->"Bold"],
"To start a new cell group, move the cursor to a position 'between' two \
existing cell groups. The cursor turns into a horizontal line. Create the \
group by simply typing something 'into' the horizontal line. A new cell \
bracket will be created. However, note that *this* text is in a separate \
bracket than the mathematica commands in the examples. When beginning a \
group (i.e. when the cursor turns into a horizontal line), you can specify \
the group type (text, normal, etc..) by going to Format...Style and chosing \
the appropriate option. By default, newly created cells are interpreted as \
being commands. However, you do not want to put regular text in command \
form:"
}], "Text"],
Cell[BoxData[
\(This\ is\ a\ command\ group . It'
s\ a\ bad\ idea\ to\ type\ text\ in\ \(here!\)\ \ Use\ the\ text\ \
setting\ for\ \ program\ \(comments!\)\)], "Input"]
}, Open ]],
Cell["", "Text"],
Cell[CellGroupData[{
Cell[TextData[{
StyleBox["Using [ ], ( ), and { }\n",
FontSize->14],
StyleBox["One of the major difficulties in first learning ",
FontSize->12,
FontWeight->"Plain"],
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Plain",
FontSlant->"Italic"],
StyleBox[" is distinguishing between brackets, braces, and parenthesis. \n\
\nSquare brackets [ ] are used to indicate the arguments of a function. For \
instance, ",
FontSize->12,
FontWeight->"Plain"]
}], "Text",
FontSize->13,
FontWeight->"Bold"],
Cell[BoxData[{
\(Cos[\[Pi]/4]\), "\[IndentingNewLine]",
\(Factor[x^2\ + \ 4 x\ - \ 12]\)}], "Input"],
Cell["\<\
Parentheses ( ) are used to group expressions or to override order of \
operation:\
\>", "Text"],
Cell[BoxData[{
\(2*5 + 8\), "\[IndentingNewLine]",
\(2*\((5 + 8)\)\)}], "Input"],
Cell["\<\
Braces { } are used for \"general grouping purposes.\" Note the \
different uses of { } in the following commands: \
\>", "Text"],
Cell[BoxData[{
\(Plot[{Cos[x], Sin[x]}, {x, 0, 2 \[Pi]}]\), "\[IndentingNewLine]",
\(\(x\ = \ {3, 5, 7};\)\), "\[IndentingNewLine]",
\(\(y = {a, b, c};\)\), "\[IndentingNewLine]",
\(x - y\)}], "Input"]
}, Open ]],
Cell["", "Text"],
Cell[CellGroupData[{
Cell[TextData[{
"Capitalization\n",
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Plain",
FontSlant->"Italic"],
StyleBox[" is case sensitive. ",
FontSize->12,
FontWeight->"Plain"],
StyleBox["Every built-in function is capitalized",
FontSize->12],
StyleBox[". Usually ",
FontSize->12,
FontWeight->"Plain"],
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Plain",
FontSlant->"Italic"],
StyleBox[" gives you informative error messages, saying \"I think you meant \
Cos[x] and not cos[x],\" but other times, you're not so lucky. \
Capitalization is usually a good place to start looking if your program \
doesn't work and you have no idea why. Try evaluating:",
FontSize->12,
FontWeight->"Plain"]
}], "Text",
FontSize->14,
FontWeight->"Bold"],
Cell[BoxData[{
\(Cos[\[Pi]]\), "\[IndentingNewLine]",
\(cos[\[Pi]]\)}], "Input"],
Cell["\<\
Also, if at one point you define X=10, don't be confused later on \
when 5*x does not equal 50. Be careful!\
\>", "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[TextData[{
"\n",
StyleBox["Function Definition",
FontSize->14,
FontWeight->"Bold"],
"\nDefining functions is also a bit tricky. First, when you define a \
function, the parameters of the function must end in a _ in the brackets. \
Second, there must be a : before the equals sign.\n\n",
StyleBox["Examples:",
FontWeight->"Bold"]
}], "Text"],
Cell[BoxData[{
\(\(f[x_] := 15 x\^2\ - \ 10 x\ + \ 3;\)\), "\[IndentingNewLine]",
\(\(g[x_,
y_] := \@\(x^2\ + \ y^2\);\)\[IndentingNewLine]\), "\
\[IndentingNewLine]",
\(f[10]\), "\[IndentingNewLine]",
\(g[2, 4]\)}], "Input"]
}, Open ]],
Cell["\<\
\
\>", "Text"],
Cell[CellGroupData[{
Cell[TextData[{
"Equality\n",
StyleBox["There are two kinds of equality. (Some variables are MORE equal \
than others...) First, there is the assignment equality: ",
FontSize->12,
FontWeight->"Plain"]
}], "Text",
FontSize->14,
FontWeight->"Bold"],
Cell[BoxData[
\(\(x = \ 10;\)\)], "Input"],
Cell["And then you can also test for equality: (does x = 10?):", "Text"],
Cell[BoxData[
\(x\ \[Equal] \ 10\)], "Input"],
Cell[" The == operator is also used in any Solve[] functions:", "Text"],
Cell[BoxData[
\(Solve[2 z \[Equal] 48, \ z]\)], "Input"],
Cell[TextData[{
"Make sure you get these right! It's another stumbling block for ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" beginners. One single = sign is very hard to pick out in a complex \
program that just ",
StyleBox["won't work",
FontSlant->"Italic"],
", so make sure you get it right the first time.",
" "
}], "Text"]
}, Open ]],
Cell["\<\
\
\>", "Text"],
Cell[TextData[{
StyleBox["Substitution\n",
FontWeight->"Bold"],
StyleBox["Another handy feature in ",
FontSize->12],
StyleBox["Mathematica",
FontSize->12,
FontSlant->"Italic"],
StyleBox[" is the ability to substitute into expressions. A substition is \
written like this:",
FontSize->12]
}], "Text",
FontSize->14],
Cell[BoxData[
\(\(\(\[IndentingNewLine]\)\(p\^2 /. \ p \[Rule] 10\)\)\)], "Input"],
Cell["Another example of the substitution rule:", "Text"],
Cell[BoxData[{
\(\(sol\ = \
Solve[p^2\ - \ 3 p\ \[Equal] \ 0, \
p];\)\), "\[IndentingNewLine]",
\(p\ /. sol\)}], "Input"],
Cell[TextData[{
"\n",
StyleBox["Plotting\n",
FontSize->14,
FontWeight->"Bold"],
"The basic syntax for plotting is:\nPlot[f[x],{x,xmin,xmax}]\n\nOther \
plotting commands include ListPlot and ParametricPlot, which have very \
similar syntax to Plot.\n"
}], "Text"],
Cell[BoxData[{
\(f[x_] := Log[x]\), "\[IndentingNewLine]",
\(Plot[Sin[x], {x, 0, 2 \[Pi]}]\), "\[IndentingNewLine]",
\(Plot[Erf[x], {x, \(-10\), 10}]\), "\[IndentingNewLine]",
\(Plot[f[x], {x, 1, 10}]\)}], "Input"],
Cell[TextData[{
StyleBox["Evaluating.",
FontWeight->"Bold"],
" One common problem with plotting functions is that ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" has not yet evaluated a function when it goes to plot it. The way to fix \
this is by using:\n\nPlot[ Evaluate[[f[x]],{x,xmin,xmax}]\n"
}], "Text"],
Cell[TextData[{
"Clearing Variables\n",
StyleBox["When you define variables in ",
FontSize->12,
FontWeight->"Plain"],
StyleBox["Mathematica",
FontSize->12,
FontWeight->"Plain",
FontSlant->"Italic"],
StyleBox[", they stay resident in memory for future use. This can be a \
problem if you have two separate parts of a worksheet, each using 'x' in a \
different way. The memory can be cleared of all variables by using the \
command:",
FontSize->12,
FontWeight->"Plain"]
}], "Text",
FontSize->14,
FontWeight->"Bold"],
Cell[BoxData[
\(Remove["\"]\)], "Input"],
Cell["\<\
It is usually a good idea to use Remove[ ] between different \
questions on your worksheet (as long as the second section does not use \
anything from the first).\
\>", "Text"],
Cell[TextData[{
"\n\n",
StyleBox["Using Help",
FontSize->26,
FontWeight->"Bold"],
"\n",
StyleBox["Mathematica",
FontSlant->"Italic"],
" has an incredible built-in help system that can very easily become your \
best friend. To see for yourself, goto Help...Built-in functions, and type \
Plot.\n\nWhat you will see is the quick-and-dirty refrence guide to using \
Plot, and all the neat things you can do with it. You can also see examples \
of several Plot statements and evaluate them for yourself.\n\nNote that at \
the bottom of the examples of Plot, you will see:"
}], "Text"],
Cell[BoxData[
\(Options[Plot]\)], "Input"],
Cell["\<\
This is a list of all the different options that go along with \
Plot. (Options[] works for any function). So if you decide to make your \
plot pretty and add color, Options[] would probably be the best place to find \
out how. \
\>", "Text"],
Cell[TextData[StyleBox["Some Commonly Used Functions",
FontWeight->"Bold"]], "Subtitle",
FontSize->16,
FontWeight->"Plain"],
Cell[TextData[{
StyleBox["N[]:",
FontWeight->"Bold"],
" Returns the numeric value of an expression."
}], "Text",
FontWeight->"Plain"],
Cell[BoxData[{
\(5/8\), "\[IndentingNewLine]",
\(N[5/8]\)}], "Input"],
Cell[TextData[{
StyleBox["Plot[]:",
FontWeight->"Bold"],
" The basic plotter in ",
StyleBox["Mathematica",
FontSlant->"Italic"],
":"
}], "Text"],
Cell[BoxData[
\(Plot[Cos[x], {x, \(-2\) \[Pi], 2 \[Pi]}]\)], "Input"],
Cell[TextData[{
StyleBox["ParametricPlot[]:",
FontWeight->"Bold"],
" Generates a parametric plot:"
}], "Text"],
Cell[BoxData[{
\(ParametricPlot[{Cos[t], Sin[2 t - \[Pi]]}, {t, 0,
5 \[Pi]}]\), "\[IndentingNewLine]",
\(ParametricPlot[{10 t, 100 - t^2}, {t, 0, 10}]\)}], "Input"],
Cell[TextData[{
StyleBox["ListPlot[]:",
FontWeight->"Bold"],
" Plots a list of values on the y axis, taking the x axis to be the \
sequence {1,2,3...}"
}], "Text"],
Cell[BoxData[
\(ListPlot[{4, 7, 2, 3, 5, 2, 3, 6}]\)], "Input"],
Cell[TextData[{
StyleBox["DSolve[]:",
FontWeight->"Bold"],
" The differential equation solver. This attempts to find solutions of \
differential equations analytically. In order for this to work, you need to \
specify the appropriate initial conditions."
}], "Text"],
Cell[BoxData[{
\(Remove["\"]\), "\[IndentingNewLine]",
\(\({x0, \ dx0} = {1, 2};\)\), "\[IndentingNewLine]",
\(DSolve[{\(x''\)[t] + 4 x[t] \[Equal] 0,
x[0] \[Equal] x0, \(x'\)[0] \[Equal] dx0}, x[t], t]\)}], "Input"],
Cell["Note the use of the == sign.", "Text"],
Cell[TextData[{
"NDSolve[]",
":",
StyleBox[" Same idea as before, only this evaluates numerically. The main \
difference is that in this case, you need to specify the limits of the \
variable to solve for. In this example, we find the solution for 0 < t < 4 \
.",
FontWeight->"Plain"]
}], "Text",
FontWeight->"Bold"],
Cell[BoxData[{
\(Remove["\"]\), "\[IndentingNewLine]",
\(\({x0, \ dx0} = {1, 2};\)\), "\[IndentingNewLine]",
\(NDSolve[{\(x''\)[t] + 4 x[t] \[Equal] 0,
x[0] \[Equal] x0, \(x'\)[0] \[Equal] dx0},
x[t], {t, 0, 4}]\)}], "Input"],
Cell[TextData[{
StyleBox["Simplify[] ",
FontWeight->"Bold"],
"and ",
StyleBox["FullSimplify[]",
FontWeight->"Bold"],
". Two of the most handy tools you'll ever come across. So you've tried \
testing someting for equality and got a screen full of junk instead of \"True\
\"? Try simplifying."
}], "Text"],
Cell[BoxData[
\(Simplify[x^2\ + 2 x\ + \ 1]\)], "Input"],
Cell[BoxData[
\(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\)\)], "Input"],
Cell[TextData[StyleBox["Things that will help you out: ",
FontWeight->"Bold"]], "Subsubtitle"],
Cell[TextData[{
"If you want help inputting functions, ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" offers a handy graphical utility. You can enable it by going to \
File...Palettes...Basic Input. This tool bar comes in handy for composing \
mathematical expressions. However, there are some keyboard shortcuts that \
you can do too. "
}], "Text"],
Cell["\<\
Most convenient of all is the escape key. If you try (ESC) + \
letter + (ESC), it will give you the greek equivalent of the letter you \
wrote. \
\>", "Text"],
Cell["\<\
The second most helpful is, when beginning a new cell group, (ATL) \
+ 7 turns it into a text group. This is handy for writing comments for the \
TA, or putting your name at the top of the paper, and so on.\
\>", "Text"],
Cell["\<\
Other keyboard shortcuts are available in the online help. Look \
under \"Other Information\" and go to 2D Expression Input.\
\>", "Text",
FontSlant->"Italic"],
Cell["\<\
Ok. Those are the basics. Are you ready to try some for yourself? Go on to \
worksheet 1...
(Don't hand this worksheet in. This one was just for refrence and example \
purposes.)\
\>", "Text"]
},
FrontEndVersion->"5.0 for Microsoft Windows",
ScreenRectangle->{{0, 1024}, {0, 685}},
CellGrouping->Manual,
WindowSize->{520, 600},
WindowMargins->{{158, Automatic}, {Automatic, 12}},
PrintingCopies->1,
PrintingPageRange->{Automatic, Automatic}
]
(*******************************************************************
Cached data follows. If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of the file. The cache data will then be recreated when
you save this file from within Mathematica.
*******************************************************************)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[1754, 51, 97, 2, 33, "Text"],
Cell[1854, 55, 47, 4, 71, "Text"],
Cell[1904, 61, 1370, 41, 261, "Text"],
Cell[CellGroupData[{
Cell[3299, 106, 780, 19, 149, "Text"],
Cell[4082, 127, 262, 7, 52, "Text"],
Cell[4347, 136, 183, 3, 70, "Input"],
Cell[4533, 141, 307, 5, 90, "Text"],
Cell[4843, 148, 56, 1, 30, "Input"],
Cell[4902, 151, 778, 13, 185, "Text"],
Cell[5683, 166, 180, 3, 50, "Input"]
}, Open ]],
Cell[5878, 172, 16, 0, 32, "Text"],
Cell[CellGroupData[{
Cell[5919, 176, 542, 17, 105, "Text"],
Cell[6464, 195, 112, 2, 43, "Input"],
Cell[6579, 199, 107, 4, 50, "Text"],
Cell[6689, 205, 89, 2, 43, "Input"],
Cell[6781, 209, 141, 3, 50, "Text"],
Cell[6925, 214, 222, 4, 75, "Input"]
}, Open ]],
Cell[7162, 221, 16, 0, 32, "Text"],
Cell[CellGroupData[{
Cell[7203, 225, 819, 26, 105, "Text"],
Cell[8025, 253, 89, 2, 43, "Input"],
Cell[8117, 257, 132, 3, 50, "Text"]
}, Open ]],
Cell[CellGroupData[{
Cell[8286, 265, 367, 10, 141, "Text"],
Cell[8656, 277, 260, 6, 98, "Input"]
}, Open ]],
Cell[8931, 286, 25, 3, 50, "Text"],
Cell[CellGroupData[{
Cell[8981, 293, 264, 8, 69, "Text"],
Cell[9248, 303, 46, 1, 27, "Input"],
Cell[9297, 306, 73, 0, 32, "Text"],
Cell[9373, 308, 50, 1, 27, "Input"],
Cell[9426, 311, 71, 0, 32, "Text"],
Cell[9500, 313, 61, 1, 27, "Input"],
Cell[9564, 316, 355, 10, 68, "Text"]
}, Open ]],
Cell[9934, 329, 25, 3, 50, "Text"],
Cell[9962, 334, 344, 12, 69, "Text"],
Cell[10309, 348, 86, 1, 45, "Input"],
Cell[10398, 351, 57, 0, 32, "Text"],
Cell[10458, 353, 155, 4, 43, "Input"],
Cell[10616, 359, 277, 8, 159, "Text"],
Cell[10896, 369, 234, 4, 75, "Input"],
Cell[11133, 375, 329, 8, 104, "Text"],
Cell[11465, 385, 555, 17, 87, "Text"],
Cell[12023, 404, 55, 1, 27, "Input"],
Cell[12081, 407, 186, 4, 50, "Text"],
Cell[12270, 413, 604, 14, 225, "Text"],
Cell[12877, 429, 46, 1, 27, "Input"],
Cell[12926, 432, 254, 5, 68, "Text"],
Cell[13183, 439, 129, 3, 57, "Subtitle"],
Cell[13315, 444, 143, 5, 32, "Text"],
Cell[13461, 451, 78, 2, 43, "Input"],
Cell[13542, 455, 161, 7, 32, "Text"],
Cell[13706, 464, 74, 1, 27, "Input"],
Cell[13783, 467, 119, 4, 32, "Text"],
Cell[13905, 473, 185, 3, 43, "Input"],
Cell[14093, 478, 172, 5, 32, "Text"],
Cell[14268, 485, 67, 1, 27, "Input"],
Cell[14338, 488, 277, 6, 68, "Text"],
Cell[14618, 496, 251, 4, 75, "Input"],
Cell[14872, 502, 44, 0, 32, "Text"],
Cell[14919, 504, 332, 9, 68, "Text"],
Cell[15254, 515, 267, 5, 75, "Input"],
Cell[15524, 522, 322, 9, 68, "Text"],
Cell[15849, 533, 63, 1, 27, "Input"],
Cell[15915, 536, 83, 1, 59, "Input"],
Cell[16001, 539, 96, 1, 53, "Subsubtitle"],
Cell[16100, 542, 367, 8, 86, "Text"],
Cell[16470, 552, 170, 4, 50, "Text"],
Cell[16643, 558, 231, 4, 68, "Text"],
Cell[16877, 564, 173, 4, 50, "Text"],
Cell[17053, 570, 207, 7, 86, "Text"]
}
]
*)
(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)