(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.2' 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[ 11791, 464]*) (*NotebookOutlinePosition[ 12517, 490]*) (* CellTagsIndexPosition[ 12473, 486]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " Tutorial" }], "Title"], Cell[CellGroupData[{ Cell["Algebraic Manipulations", "Section"], Cell[BoxData[ \(\(Expression1 = EnzS[t]\ \((1 + \(k1b + k2f\)\/\(\(k1f\)\(\ \)\))\) \[Equal] S[t];\)\)], "Input", CellLabel->"In[11]:="], Cell[TextData[{ "In ", StyleBox["Mathematica", FontSlant->"Italic"], ", every object (from equations, to numerical solutions and graphics) is \ represented as an expression. All expressions have a 'Head', that tells you \ what type of expression the object is. In ", StyleBox["Mathematica", FontSlant->"Italic"], ", one can find out information of commands by typing ", StyleBox["?Command", FontWeight->"Bold"], ". So, to find out what head does, type and evaluate:" }], "Text"], Cell[BoxData[ \(\(?Head\)\)], "Input", CellLabel->"In[17]:="], Cell[TextData[{ "Now find out what head ", StyleBox["Expression1", FontWeight->"Bold"], " has." }], "Text"], Cell[BoxData[""], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "In ", StyleBox["Mathematica", FontSlant->"Italic"], ", functions can be written in the ", StyleBox["Prefix", FontWeight->"Bold"], " form as well as the ", StyleBox["Postfix", FontWeight->"Bold"], " form. As an example for showing the two (equivalent) ways to input \ expressions, evaluate and compare the following:" }], "Text"], Cell[BoxData[{ \(Head[Expression1]\[IndentingNewLine]\), "\[IndentingNewLine]", \(Expression1 // Head\)}], "Input"], Cell[TextData[{ "What does it mean that objects are expressions? To look at how ", StyleBox["Expression1", FontWeight->"Bold"], " is represented, use the command ", StyleBox["FullForm", FontWeight->"Bold"], ":" }], "Text"], Cell[BoxData[ \(Expression1 // FullForm\)], "Input"], Cell[TextData[{ "As another (visual) representation of the same expression, use ", StyleBox["TreeForm", FontWeight->"Bold"] }], "Text"], Cell[BoxData[ \(Expression1 // TreeForm\)], "Input"], Cell[TextData[{ "How do we extract elements of expressions? Use commands ", StyleBox["Last", FontWeight->"Bold"], " and ", StyleBox["First", FontWeight->"Bold"], ". Find out what they do below, and find out what are the ", StyleBox["Last", FontWeight->"Bold"], " and ", StyleBox["Head", FontWeight->"Bold"], " of ", StyleBox["Expression1", FontWeight->"Bold"], "." }], "Text"], Cell[BoxData[""], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "The command ", StyleBox["Together", FontWeight->"Bold"], " is useful in cancelling factors in a common denominator. Find out what it \ does, and factor the left-hand-side of ", StyleBox["Expression1", FontWeight->"Bold"], ", using combination of ", StyleBox["First", FontWeight->"Bold"], " and ", StyleBox["Together", FontWeight->"Bold"], ". " }], "Text"], Cell[BoxData[""], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "For comparison, we see that applying ", StyleBox["Together", FontWeight->"Bold"], " on ", StyleBox["Expression 1", FontWeight->"Bold"], " fails to get the desired result." }], "Text"], Cell[BoxData[ \(Expression1 // Together\)], "Input"], Cell[TextData[{ "The problem arises from the fact that the term ", Cell[BoxData[ \(\((1 + \(k1b + k2f\)\/k1f)\)\)]], "is a subexpression, i.e., not at the first level of ", StyleBox["Expression1", FontWeight->"Bold"], ". To obtain the desired result, we should map ", StyleBox["Together", FontWeight->"Bold"], " to all subexpressions. Find out what ", StyleBox["MapAll", FontWeight->"Bold"], " does, and apply it to ", StyleBox["Expression1", FontWeight->"Bold"], ". Complete the following:" }], "Text"], Cell[BoxData[ \(\(?MapAll\)\)], "Input"], Cell[BoxData[ \(\(\(Together\)\(//@\)\(\ \ \ \ \ \)\)\)], "Input", Background->RGBColor[0, 1, 1]], Cell["\<\ The command Thread is useful in writing down a system of equations, \ equating a list of left-hand-side to a list of right-hand-side. Simply \ equating the lists do not work:\ \>", "Text"], Cell[BoxData[{ \(\(LHS = {a, b, c};\)\), "\[IndentingNewLine]", \(\(\(RHS = {1, 2, 3};\)\(\[IndentingNewLine]\) \)\), "\[IndentingNewLine]", \(LHS \[Equal] RHS\)}], "Input"], Cell[TextData[{ "To equate the individual terms, one needs to apply ", StyleBox["Thread", FontWeight->"Bold"], "; see what happens:" }], "Text"], Cell[BoxData[ \(Thread[{a, b, c} == {1, 2, 3}]\)], "Input"], Cell[CellGroupData[{ Cell["Perturbation Analysis", "Subsection"], Cell["\<\ Suppose one has algebraic equation obtained from perturbative \ analysis, e.g.,\ \>", "Text"], Cell[BoxData[ \(\(PertEqn = \((La\ + \ Lb\ \[Epsilon])\)*\((Lc + Ld\ \[Epsilon])\) + Lf\ \[Epsilon]\^2 \[Equal] \ Ra\ + \ \((Rb + Ra)\)*\[Epsilon]\ + \ Rc\ \[Epsilon]\^2;\)\)], "Input"], Cell["\<\ One would like to equate equal powers of left and right-hand sides.\ \ \>", "Text"], Cell["Firstly, obtain the LHS of PertEqn below:", "Text"], Cell[BoxData[{ \(\(\(\(PertEqnLHS\)\(\ \)\(=\)\)\ \ \ \ ;\)\[IndentingNewLine]\), "\ \[IndentingNewLine]", \(\(\(\(PertEqnRHS\)\(\ \)\(=\)\)\ \ \ \ ;\)\)}], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "The terms of each order in ", "\[Epsilon] ", "can be obtained using the command ", StyleBox["CoefficientList", FontWeight->"Bold"] }], "Text"], Cell[BoxData[ \(\(?CoefficientList\)\)], "Input"], Cell[TextData[{ "Using ", StyleBox["CoefficientList", FontWeight->"Bold"], ", obtain a list of equations matching LHS and RHS, for each order in ", StyleBox["\[Epsilon]", FontWeight->"Bold"], ". Hint: use ", StyleBox["Thread", FontWeight->"Bold"], " to equate each term in the LHS and RHS lists. Complete the following:" }], "Text"], Cell[BoxData[{ \(\(LHSCoefficientList = CoefficientList[\ , \ ];\)\), "\[IndentingNewLine]", \(\(\(\(\(RHSCoefficientList\)\(=\)\)\ \ \ \ ;\)\(\[IndentingNewLine]\) \)\), "\[IndentingNewLine]", \(\(OrderEqn\ = \ \ Thread[\ \ \ \ ];\)\ \)}], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "\nNow, let's extract the RHS unknowns, based on the following hint using \ the command ", StyleBox["Cases", FontWeight->"Bold"] }], "Text"], Cell[BoxData[ \(\(?Cases\)\)], "Input"], Cell[TextData[{ "As an example on using ", StyleBox["Cases", FontWeight->"Bold"], " to extract all symbols from a expression, evaluate below:" }], "Text"], Cell[BoxData[ \(Cases[{a + b, \ c*d/f + f, \ 2.0*5 + g}, \ _Symbol, \ Infinity]\)], "Input"], Cell[TextData[{ "Try a call to Cases, apply it to ", StyleBox["RHSCoefficientList", FontWeight->"Bold"] }], "Text"], Cell[BoxData[ \(\(\(\(RHS\[UnderBracket]Unknowns\)\(=\)\)\ \ \ \ ;\)\)], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "Now, ", StyleBox["RHS\[UnderBracket]Unknowns", FontWeight->"Bold"], " contains repeated terms. Remove these redundant elements, by using the \ command Union:" }], "Text"], Cell[BoxData[ \(\(?Union\)\)], "Input"], Cell[TextData[{ "Apply ", StyleBox["Union ", FontWeight->"Bold"], "to ", StyleBox["RHS\[UnderBracket]Unknowns", FontWeight->"Bold"], StyleBox[", and over-write the result:", FontVariations->{"CompatibilityType"->0}] }], "Text"], Cell[BoxData[ \(\(\(\(\(RHS\[UnderBracket]Unknowns\)\(=\)\)\ \ \ \ \ ;\)\(\ \ \)\)\)], \ "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "Let's now solve ", StyleBox["OrderEqn", FontWeight->"Bold"], ", with respect to ", StyleBox["RHS\[UnderBracket]Unknowns", FontWeight->"Bold"], ", using the command ", StyleBox["Solve", FontWeight->"Bold"], ":" }], "Text"], Cell[BoxData[ \(\(?Solve\)\)], "Input"], Cell[BoxData[ \(\(\(\(RHS\[UnderBracket]Soln = \ Solve[\ \ \ ];\)\[IndentingNewLine] % // ColumnForm\)\(\ \ \ \ \ \ \ \)\)\)], "Input", Background->RGBColor[0, 1, 1]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Numerical Integration", "Section"], Cell[TextData[{ "To numerically integrate ordinary differential equations, the function ", StyleBox["NDSolve", FontWeight->"Bold"], " is used." }], "Text"], Cell[BoxData[ \(\(?NDSolve\)\)], "Input"], Cell[TextData[{ "Lets now solve the ODE system\n\n", Cell[BoxData[ FormBox[ StyleBox[\(dy\/dt = \(-y\) + 1\), FontColor->RGBColor[0, 0, 1]], TraditionalForm]]], "\n\nsubject to the initial condition ", StyleBox["y[0]=2", FontColor->RGBColor[0, 0, 1]], ". \n\nComplete the following" }], "Text"], Cell[BoxData[ \(\(?D\)\)], "Input"], Cell[BoxData[ \(\(ODE = D[\ \ , ]\ \ \ ;\)\)], "Input", Background->RGBColor[0, 1, 1]], Cell["\<\ Also, we need the initial condition. Complete below:\ \>", "Text"], Cell[BoxData[ \(\(\(\(IC\)\(\ \)\(=\)\)\ \ \ ;\)\)], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "\nNow, combine ", StyleBox["ODE", FontWeight->"Bold"], " and ", StyleBox["IC", FontWeight->"Bold"], " into a single List, and call it ", StyleBox["ODE\[UnderBracket]IC", FontWeight->"Bold"] }], "Text"], Cell[BoxData[ \(\(\(\(ODE\[UnderBracket]IC\)\(=\)\)\ \ ;\)\)], "Input", Background->RGBColor[0, 1, 1]], Cell[TextData[{ "Now, using ", StyleBox["NDSolve", FontWeight->"Bold"], ", compute the solution from t=0 to t=5." }], "Text"], Cell[BoxData[ \(\(\(\(NumericSoln\)\(=\)\)\ \ ;\)\)], "Input", Background->RGBColor[0, 1, 1]], Cell["Lets now plot the solution.", "Text"], Cell[BoxData[ \(\(?Plot\)\)], "Input"], Cell["Complete the following:", "Text"], Cell[BoxData[ \(\(Plot[\ \(y[t] /. NumericSoln\)\(,\)\ \ \ ];\)\)], "Input", Background->RGBColor[0, 1, 1]] }, Open ]] }, Open ]] }, FrontEndVersion->"5.2 for X", ScreenRectangle->{{0, 1400}, {0, 1050}}, WindowSize->{1139, 942}, WindowMargins->{{Automatic, 88}, {Automatic, 0}}, ShowSelection->True, ShowCellLabel->False, Magnification->1.5, StyleDefinitions -> "Report.nb" ] (******************************************************************* 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[CellGroupData[{ Cell[1776, 53, 94, 4, 125, "Title"], Cell[CellGroupData[{ Cell[1895, 61, 42, 0, 102, "Section"], Cell[1940, 63, 162, 4, 76, "Input"], Cell[2105, 69, 504, 13, 87, "Text"], Cell[2612, 84, 67, 2, 46, "Input"], Cell[2682, 88, 117, 5, 41, "Text"], Cell[2802, 95, 59, 1, 46, "Input"], Cell[2864, 98, 371, 12, 64, "Text"], Cell[3238, 112, 124, 2, 92, "Input"], Cell[3365, 116, 240, 8, 41, "Text"], Cell[3608, 126, 56, 1, 46, "Input"], Cell[3667, 129, 143, 4, 41, "Text"], Cell[3813, 135, 56, 1, 46, "Input"], Cell[3872, 138, 418, 17, 64, "Text"], Cell[4293, 157, 59, 1, 46, "Input"], Cell[4355, 160, 406, 15, 64, "Text"], Cell[4764, 177, 59, 1, 46, "Input"], Cell[4826, 180, 218, 8, 41, "Text"], Cell[5047, 190, 56, 1, 46, "Input"], Cell[5106, 193, 547, 17, 95, "Text"], Cell[5656, 212, 44, 1, 46, "Input"], Cell[5703, 215, 103, 2, 46, "Input"], Cell[5809, 219, 198, 4, 64, "Text"], Cell[6010, 225, 191, 4, 115, "Input"], Cell[6204, 231, 154, 5, 41, "Text"], Cell[6361, 238, 63, 1, 46, "Input"], Cell[CellGroupData[{ Cell[6449, 243, 43, 0, 62, "Subsection"], Cell[6495, 245, 103, 3, 41, "Text"], Cell[6601, 250, 229, 4, 51, "Input"], Cell[6833, 256, 93, 3, 41, "Text"], Cell[6929, 261, 57, 0, 41, "Text"], Cell[6989, 263, 207, 4, 92, "Input"], Cell[7199, 269, 171, 6, 41, "Text"], Cell[7373, 277, 53, 1, 46, "Input"], Cell[7429, 280, 358, 11, 64, "Text"], Cell[7790, 293, 310, 6, 115, "Input"], Cell[8103, 301, 164, 5, 64, "Text"], Cell[8270, 308, 43, 1, 46, "Input"], Cell[8316, 311, 164, 5, 41, "Text"], Cell[8483, 318, 103, 2, 46, "Input"], Cell[8589, 322, 123, 4, 41, "Text"], Cell[8715, 328, 118, 2, 46, "Input"], Cell[8836, 332, 197, 6, 41, "Text"], Cell[9036, 340, 43, 1, 46, "Input"], Cell[9082, 343, 249, 9, 41, "Text"], Cell[9334, 354, 134, 3, 46, "Input"], Cell[9471, 359, 264, 11, 41, "Text"], Cell[9738, 372, 43, 1, 46, "Input"], Cell[9784, 375, 176, 3, 69, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[10009, 384, 40, 0, 102, "Section"], Cell[10052, 386, 165, 5, 41, "Text"], Cell[10220, 393, 45, 1, 46, "Input"], Cell[10268, 396, 332, 10, 187, "Text"], Cell[10603, 408, 39, 1, 46, "Input"], Cell[10645, 411, 92, 2, 46, "Input"], Cell[10740, 415, 77, 3, 64, "Text"], Cell[10820, 420, 98, 2, 46, "Input"], Cell[10921, 424, 242, 10, 64, "Text"], Cell[11166, 436, 108, 2, 46, "Input"], Cell[11277, 440, 135, 5, 41, "Text"], Cell[11415, 447, 99, 2, 46, "Input"], Cell[11517, 451, 43, 0, 41, "Text"], Cell[11563, 453, 42, 1, 46, "Input"], Cell[11608, 456, 39, 0, 41, "Text"], Cell[11650, 458, 113, 2, 46, "Input"] }, Open ]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)