(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 4.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[ 5644, 164]*) (*NotebookOutlinePosition[ 6288, 186]*) (* CellTagsIndexPosition[ 6244, 182]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Math 222: Sample notebook for Lab #2", "Title", FontSize->24], Cell[CellGroupData[{ Cell["The If Command", "Section"], Cell[TextData[{ "In your design of the golden section search, you will probably want to use \ ", StyleBox["Mathematica", FontSlant->"Italic"], "'s If command. This command allows you to do different things according \ to some condition. Its syntax is:\n\nIf[condition, command1, command2]\n\n", StyleBox["Mathematica", FontSlant->"Italic"], " will do command1 if \"condition\" is true; otherwise it will do command2. \ Each of \"command1\" and \"command2\" can include multiple commands if you \ separate them by semicolons. Here is an example that prints \"Hi\" and the \ number 3 if x is positive, and otherwise prints 30 digits of Pi." }], "Text", FontSize->18], Cell[BoxData[{ \(\(x = 1;\)\), "\[IndentingNewLine]", \(If[x > 0, \ \ \ Print["\"]; \ 3, \ \ \ \ N[Pi, 30]]\)}], "Input"], Cell[BoxData[{ \(\(x = \(-1\);\)\), "\[IndentingNewLine]", \(If[x > 0, \ \ \ Print["\"]; \ 3, \ \ \ \ N[Pi, 30]]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["The Golden Section search", "Section"], Cell["\<\ Here's the golden section code I demonstrated in class. Read it \ through to make sure you understand the pieces, and then apply it to your \ problem.\ \>", "Text", FontSize->18], Cell[BoxData[{ \(\(gm\ = \ \((Sqrt[5.0`15] - 1.0`15)\)/ 2.0`15;\)\), "\[IndentingNewLine]", \(\(fcounter\ = \ 0;\)\), "\[IndentingNewLine]", \(\(a = 0.0`15;\)\), "\[IndentingNewLine]", \(\(b = 1.0`15;\)\), "\[IndentingNewLine]", \(While[ b - a\ > \ 0.0000000001, \[IndentingNewLine]c\ = \ a + gm*\((b - a)\); \[IndentingNewLine]d\ = \ a + gm^2*\((b - a)\); \[IndentingNewLine]If[\((f[a] - f[d])\)*\((f[d] - f[c])\) < 0, b = c, a = d]; \[IndentingNewLine]fcounter = fcounter + 1; \[IndentingNewLine]Print[{a, b}]\[IndentingNewLine]]\), "\[IndentingNewLine]", \(Print["\", fcounter]\), "\[IndentingNewLine]", \(\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["The FindMinimum command", "Section"], Cell[TextData[{ "In your optimization problem, you will use ", StyleBox["Mathematica", FontSlant->"Italic"], "'s FindMinimum command to minimize or maximize a function of several \ variable. FindMinimum uses a farily sophisticated quasi-Newton method, \ roughly of the type we discussed at the end of our minimization unit.\n\n\ There are two possible syntaxes for FindMinimum, illustrated below for a \ function f of 3 variables x, y, z:\n\n\ FindMinimum[f[x,y,z],{x,x0},{y,y0},{z,z0}]\n\nor \n\n\ FindMinimum[f[x,y,z],{x,{x0,x1}},{y,{y0,y1}},{z,{z0,z1}}]\n\nIn the first \ case, you provide a single initial guess for each of the unknowns x, y, and \ z. This method will only work if ", StyleBox["Mathematica", FontSlant->"Italic"], " is able to differentiate f symbolically (you don't have to be able to do \ the differentiation, but ", StyleBox["Mathematica", FontSlant->"Italic"], " will need to be able to). In the second case, you provide two initial \ guesses for each of the unknowns (this method works even when f can not be \ differentiated symbolically).\n\nHere is an example:" }], "Text", FontSize->18], Cell[BoxData[ \(Clear[x, y, z]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(FindMinimum[\((x - 2)\)^2 + \((y - 3)\)^2 + \((z - 4)\)^2 + 7, {x, 3}, {y, 4}, {z, 5}]\)], "Input"], Cell[BoxData[ \({7.`, {x \[Rule] 2.`, y \[Rule] 3.`, z \[Rule] 4.`}}\)], "Output"] }, Open ]], Cell["\<\ Note that the output gives us first the minimum value of the function, \ followed by a \"rule\" for what x,y,z are at the minimum.\ \>", "Text", FontSize->18] }, Open ]] }, Open ]] }, FrontEndVersion->"4.2 for Microsoft Windows", ScreenRectangle->{{0, 1400}, {0, 967}}, WindowSize->{1046, 823}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (******************************************************************* 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, 69, 1, 101, "Title"], Cell[CellGroupData[{ Cell[1870, 58, 33, 0, 59, "Section"], Cell[1906, 60, 688, 14, 206, "Text"], Cell[2597, 76, 135, 2, 50, "Input"], Cell[2735, 80, 140, 2, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2912, 87, 44, 0, 59, "Section"], Cell[2959, 89, 191, 5, 62, "Text"], Cell[3153, 96, 757, 15, 270, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3947, 116, 42, 0, 59, "Section"], Cell[3992, 118, 1147, 23, 446, "Text"], Cell[5142, 143, 47, 1, 30, "Input"], Cell[CellGroupData[{ Cell[5214, 148, 128, 2, 30, "Input"], Cell[5345, 152, 86, 1, 29, "Output"] }, Open ]], Cell[5446, 156, 170, 4, 38, "Text"] }, Open ]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)