(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 10.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 51032, 1304] NotebookOptionsPosition[ 47035, 1170] NotebookOutlinePosition[ 47447, 1188] CellTagsIndexPosition[ 47404, 1185] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Making interactive models", "Title", CellChangeTimes->{{3.618738912487796*^9, 3.6187389299386044`*^9}, { 3.619324653486854*^9, 3.619324660533725*^9}, {3.619326731634856*^9, 3.619326739015965*^9}, {3.650887349344263*^9, 3.650887393527779*^9}, { 3.651464360685463*^9, 3.6514643645113773`*^9}, {3.651467028105948*^9, 3.651467062389612*^9}}], Cell[CellGroupData[{ Cell["Manipulate[...]", "Section", CellChangeTimes->{{3.618763068734948*^9, 3.6187630938146772`*^9}, { 3.619141486610537*^9, 3.619141492926496*^9}, {3.65146709971838*^9, 3.651467106520555*^9}}], Cell[TextData[StyleBox["Using the command Manipulate[...] we can turn a \ static computation or graph into a dynamic and sophisticated model. We can \ wrap Manipulate[...] around any Wolfram command to create an interactive \ model. We need to introduce a parameter that we want to manipulate and some \ bounds for that parameter. ", "Subsubsection", FontColor->GrayLevel[0]]], "Text", CellChangeTimes->{{3.61914149719843*^9, 3.6191415458687487`*^9}, { 3.619144411008965*^9, 3.619144447675994*^9}, {3.619144533114852*^9, 3.619144563423238*^9}, {3.619144660390873*^9, 3.619144690722156*^9}, { 3.619146725854446*^9, 3.619146759990509*^9}, {3.619147099274131*^9, 3.6191471081783953`*^9}}, TextJustification->1.], Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Parameter ranges are given inside curly brackets: ", FontColor->GrayLevel[0]], "\n", StyleBox["{x, 4, 7}", FontColor->GrayLevel[0]], " -- specifies an interval [4,7] that the parameter x belongs to.\n", StyleBox["{x, {4,7}}", FontColor->GrayLevel[0]], " -- specifies a discrete set of values that x can take on.\n", StyleBox["{{x, 5, \[OpenCurlyDoubleQuote]Some text describing the meaning of \ the parameter x\[CloseCurlyDoubleQuote]}, 4,7} ", FontColor->GrayLevel[0]], " -- x belongs to the interval [4,7] and the default value is 5" }], "Subsubsection", CellChangeTimes->{{3.6191467693238573`*^9, 3.619146950356045*^9}, { 3.619151086286968*^9, 3.619151140449494*^9}, {3.619151279939712*^9, 3.619151417605892*^9}, {3.619151535475821*^9, 3.619151555312394*^9}, { 3.619151607803134*^9, 3.619151635421248*^9}, {3.619151711650279*^9, 3.6191517176736727`*^9}, {3.6191518115360126`*^9, 3.619151826517083*^9}, { 3.6514633823847218`*^9, 3.65146338517836*^9}, {3.6960538227692833`*^9, 3.696053829873169*^9}}], Cell[TextData[{ StyleBox["\nHelp->Demonstrations gives you a list of pre-built ", "Subsubsection", FontColor->GrayLevel[0]], StyleBox[ButtonBox["Wolfram Demonstration Projects", BaseStyle->"Hyperlink", ButtonData->{ URL["http://demonstrations.wolfram.com/"], None}, ButtonNote->"http://demonstrations.wolfram.com/"], FontSize->16, FontWeight->"Bold"], StyleBox[". They all use the command Manipulate[...]. You can browse by \ topic and see the available templates. You can then download the project as a \ .cdf, which means that you get an interactive version that you can run \ locally on your computer, or you can download the author code, which means \ that you get a notebook (.nb) with the necessary code to generate the model.", "Subsubsection", FontColor->GrayLevel[0]] }], "Text", CellChangeTimes->{{3.6191488891318197`*^9, 3.619148979369378*^9}, { 3.619149274230813*^9, 3.619149289604766*^9}, {3.619150000298657*^9, 3.619150169057393*^9}, {3.619150317437633*^9, 3.6191503369626293`*^9}, { 3.6191533487345333`*^9, 3.619153348737863*^9}, 3.619328952479558*^9, 3.6514648619417973`*^9, {3.6514649336167297`*^9, 3.6514649500477343`*^9}, 3.651483645551116*^9}, TextJustification->1., FontSize->12, FontColor->GrayLevel[0]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["An Interactive Model", "Section", CellChangeTimes->{{3.620445937842271*^9, 3.620445947497551*^9}, { 3.6204472736480217`*^9, 3.6204472825498543`*^9}, {3.69605144059136*^9, 3.696051448061973*^9}}], Cell[CellGroupData[{ Cell["\<\ Example 1. Make an interactive model that computes n^2, for n in the interval \ [1,4].\ \>", "Subsection", CellDingbat->"\[FilledSquare]", CellChangeTimes->{{3.6204459738089523`*^9, 3.6204460536405697`*^9}, { 3.6204462152671022`*^9, 3.6204462159137497`*^9}, {3.620446287434054*^9, 3.6204463030498953`*^9}, 3.6204463496461906`*^9, {3.620447091230641*^9, 3.620447096110468*^9}, 3.620447294151079*^9, {3.6205028594316874`*^9, 3.6205028623514967`*^9}}], Cell[CellGroupData[{ Cell["Solution 1", "Subsubsection", CellDingbat->"\[HappySmiley]", CellChangeTimes->{{3.62044623392955*^9, 3.620446246505555*^9}, { 3.6204493190188932`*^9, 3.620449330855113*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell["\<\ If you click the plus sign at the end of the slider, you get a set of video \ controls. You can introduce a particular value of the parameter and hit Enter \ to jump to that value. When you do a presentation, you can also hide the \ Wolfram commands and show only the interactive model. Once an interactive \ model is created, you can copy and run the model in a new notebook. You do \ not need to copy the code, only the model.\ \>", "Text", CellChangeTimes->{{3.651886341448072*^9, 3.6518864676769447`*^9}, { 3.69605147649697*^9, 3.6960514807348003`*^9}, {3.696051645653059*^9, 3.6960516476600323`*^9}, {3.696051785965911*^9, 3.696051791790957*^9}}, TextJustification->1.], Cell["\<\ We can also set a default value for n when we call Manipulate[..]. The \ example below assumes that n=3 is the default value.\ \>", "Text", CellChangeTimes->{{3.651482432634801*^9, 3.6514824637357063`*^9}, 3.6514825235396767`*^9, {3.696051802631248*^9, 3.696051825942528*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "3"}], "}"}], ",", "1", ",", "4"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6514824774711647`*^9, 3.651482482529368*^9}, { 3.6960518371833076`*^9, 3.6960518376391497`*^9}}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]], Cell[CellGroupData[{ Cell["We can indicate the domain of n in different ways!", "Subsubsection", CellDingbat->"\[HappySmiley]", CellChangeTimes->{{3.62044623392955*^9, 3.620446246505555*^9}, { 3.6204493190188932`*^9, 3.620449330855113*^9}, 3.6514633956786537`*^9, { 3.651463570945133*^9, 3.6514635788307543`*^9}, {3.651463682034605*^9, 3.6514636839239063`*^9}, {3.651464345047111*^9, 3.651464345589898*^9}}], Cell["\<\ We can indicate the domain of n in different ways (each way will generate a \ different type of control button, slider, popup menu, checkbox, etc.)\ \>", "Text", CellChangeTimes->{{3.621011393206677*^9, 3.621011449302083*^9}, { 3.621011479568572*^9, 3.621011522205966*^9}, {3.621011719406851*^9, 3.621011721461596*^9}, {3.6518891677060957`*^9, 3.6518892151009617`*^9}}], Cell["\<\ In the two examples below, n takes values between 1 and 4 in steps of 0.25 \ and respectively in steps of 1. The Manipulate command creates a slider. \ \>", "Text", CellChangeTimes->{{3.621011393206677*^9, 3.621011449302083*^9}, { 3.621011479568572*^9, 3.621011522205966*^9}, {3.621011719406851*^9, 3.621011721461596*^9}, {3.651463412847378*^9, 3.651463485899906*^9}, { 3.6514635218377523`*^9, 3.6514635479383373`*^9}, {3.6514636870703793`*^9, 3.651463694968747*^9}, {3.651464153581397*^9, 3.651464171221727*^9}, { 3.696051954842574*^9, 3.696052020146824*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4", ",", "0.25"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}, {3.621011251049992*^9, 3.621011251624877*^9}, { 3.6210115953399677`*^9, 3.621011624881946*^9}, 3.621011659647911*^9}, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4", ",", "1"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}, {3.621011251049992*^9, 3.621011251624877*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell["\<\ Instead of incrementing n in steps of 1, we can enumerate the list of \ possible values for n. The Manipulate command will create a button for each \ possible value.\ \>", "Text", CellChangeTimes->{{3.651463926422414*^9, 3.651464069483131*^9}, { 3.651464112434198*^9, 3.651464136781116*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{"1", ",", "2", ",", "3", ",", "4"}], "}"}]}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}, {3.6210113409889507`*^9, 3.6210113464123077`*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell["\<\ If the list of possible values for n is too large, then a drop - down list \ will be created.\ \>", "Text", CellChangeTimes->{{3.6514638013810377`*^9, 3.651463882390463*^9}, { 3.651464039812584*^9, 3.6514640518985357`*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{ "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8", ",", "9"}], "}"}]}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}, {3.6210113409889507`*^9, 3.6210113464123077`*^9}, { 3.651463756150182*^9, 3.651463756414028*^9}, {3.6514638937867947`*^9, 3.6514638955859833`*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell["\<\ If no interval for n is given, Manipulate will create an empty text box where \ you can type in the value for n, then click Enter to obtain the result .\ \>", "Text", CellChangeTimes->{{3.6514639126299143`*^9, 3.651463916671432*^9}, { 3.651464094496717*^9, 3.6514641050775547`*^9}, {3.6514641933156633`*^9, 3.651464220997931*^9}, {3.6514642648707438`*^9, 3.651464296021432*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", "n", "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6514642345127087`*^9, 3.651464241411213*^9}}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Options for the controls can also be given within the specification for the \ variables. \ \>", "Subsubsection", CellDingbat->"\[HappySmiley]", CellChangeTimes->{{3.62044623392955*^9, 3.620446246505555*^9}, { 3.6204493190188932`*^9, 3.620449330855113*^9}, 3.6514633956786537`*^9, { 3.651463570945133*^9, 3.6514635788307543`*^9}, {3.651463682034605*^9, 3.6514636839239063`*^9}, {3.651464345047111*^9, 3.651464345589898*^9}, { 3.696052106014018*^9, 3.6960521106541777`*^9}}], Cell[TextData[{ "The option setting ", StyleBox["ControlType\[RightArrow]type", FontWeight->"Bold"], " attempts to use controls of the specified type. Possible control types \ include: Animator, Checkbox, CheckboxBar, ColorSetter, ColorSlider, \ InputField, Manipulator, PopupMenu, RadioButton or RadioButtonBar, Setter or \ SetterBar, Slider, Slider2D, TogglerBar, Trigger, and VerticalSlider, None. \ More information can be found in the ", ButtonBox["Mathematica Documentation", BaseStyle->"Hyperlink", ButtonData->{ URL["https://reference.wolfram.com/language/ref/Manipulate.html"], None}, ButtonNote->"https://reference.wolfram.com/language/ref/Manipulate.html"], ". \nThe option setting ", StyleBox["ControlPlacement\[RightArrow]pos", FontWeight->"Bold"], " specifies that controls should be placed at position pos relative to expr. \ Possible settings for position are Bottom, Left, Right, and Top. " }], "Text", CellChangeTimes->{{3.651888933519823*^9, 3.651888982392406*^9}, 3.651889037187768*^9, {3.651889232229822*^9, 3.65188923499015*^9}, 3.651889320788073*^9, {3.651889419858892*^9, 3.6518894256914463`*^9}, { 3.651890458505724*^9, 3.6518904948583593`*^9}, {3.651892787275588*^9, 3.6518928279266043`*^9}, {3.6518929115416307`*^9, 3.6518929462560053`*^9}, {3.696051508559993*^9, 3.696051520680084*^9}, { 3.696051562362314*^9, 3.696051564049934*^9}, {3.6960521147418222`*^9, 3.696052116749984*^9}}, TextJustification->1.], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{ "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8"}], "}"}], ",", RowBox[{"ControlType", "\[Rule]", "SetterBar"}]}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}, {3.6210113409889507`*^9, 3.6210113464123077`*^9}, { 3.651889021456698*^9, 3.651889045237002*^9}, {3.6518893259388037`*^9, 3.6518893293649063`*^9}, {3.651889386836069*^9, 3.651889408957242*^9}, { 3.6518894845824137`*^9, 3.651889496184812*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{ "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8"}], "}"}], ",", RowBox[{"ControlType", "->", "PopupMenu"}], ",", " ", RowBox[{"ControlPlacement", "\[Rule]", "Left"}]}], "}"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}, {3.6210113409889507`*^9, 3.6210113464123077`*^9}, { 3.651889021456698*^9, 3.651889045237002*^9}, {3.651889085322031*^9, 3.6518890961574087`*^9}, {3.6518928473487387`*^9, 3.651892876059514*^9}, { 3.651892970971458*^9, 3.6518930005658073`*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"n", "^", "2"}], ",", " ", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{ "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8"}], "}"}], ",", RowBox[{"ControlType", "\[Rule]", "VerticalSlider"}]}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6204457491544952`*^9, 3.6204457624236317`*^9}, { 3.620445796679528*^9, 3.620445865958887*^9}, {3.620445916707213*^9, 3.620445919602244*^9}, {3.6210113409889507`*^9, 3.6210113464123077`*^9}, { 3.651889021456698*^9, 3.651889045237002*^9}, {3.651889085322031*^9, 3.651889123291037*^9}, {3.651889467939324*^9, 3.6518894815426083`*^9}, { 3.6518901683766193`*^9, 3.651890227131242*^9}}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Same Interactive Model, but different implementations", "Section", CellChangeTimes->{{3.620445937842271*^9, 3.620445947497551*^9}, { 3.6204472736480217`*^9, 3.6204472825498543`*^9}, {3.69605144059136*^9, 3.696051448061973*^9}, {3.696052203976405*^9, 3.696052217687484*^9}}], Cell[CellGroupData[{ Cell["\<\ Example 1. Make an interactive model that computes n^2, for n in the interval \ [1,4].\ \>", "Subsection", CellDingbat->"\[FilledSquare]", CellChangeTimes->{{3.6204459738089523`*^9, 3.6204460536405697`*^9}, { 3.6204462152671022`*^9, 3.6204462159137497`*^9}, {3.620446287434054*^9, 3.6204463030498953`*^9}, 3.6204463496461906`*^9, {3.620447091230641*^9, 3.620447096110468*^9}, 3.620447294151079*^9, {3.6205028594316874`*^9, 3.6205028623514967`*^9}}], Cell[CellGroupData[{ Cell["Solution 2", "Subsubsection", CellDingbat->"\[SadSmiley]", CellChangeTimes->{{3.62044625382576*^9, 3.620446256585589*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"temp", "=", "n"}], ";", "\[IndentingNewLine]", RowBox[{"temp", "=", RowBox[{"temp", "^", "2"}]}], ";", "\[IndentingNewLine]", "temp"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellChangeTimes->{{3.620445576655717*^9, 3.6204456129891768`*^9}, { 3.6204460732845583`*^9, 3.6204460784567842`*^9}, {3.620446468432815*^9, 3.620446558674715*^9}, {3.620446635240773*^9, 3.620446640385438*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell[TextData[{ StyleBox["Notice that the cell reevaluates itself continuously", FontColor->RGBColor[1, 0, 0]], " ", StyleBox["(the right cell bracket is constantly blinking), even when we do \ not change the position of the slider", FontColor->RGBColor[1, 0, 0]], ". You can confirm this by going to Evaluation->Find Currently Evaluating \ Cell. This happens because the variable temp has its value changed during the \ evaluation (temp =temp^2), even if the value of n has not changed." }], "Text", CellChangeTimes->{{3.620446361596903*^9, 3.6204464608855124`*^9}, { 3.620447337910591*^9, 3.620447362064291*^9}, {3.620492722044738*^9, 3.620492820335494*^9}, 3.696052274949729*^9}, TextJustification->1.] }, Open ]], Cell[CellGroupData[{ Cell["Solution 3", "Subsubsection", CellDingbat->"\[HappySmiley]", CellChangeTimes->{{3.620446264785718*^9, 3.6204462671459303`*^9}}], Cell[TextData[{ "The problem can be solved by making the ", StyleBox["global variable", FontColor->RGBColor[1, 0, 0]], " \[OpenCurlyDoubleQuote]temp\[CloseCurlyDoubleQuote] be ", StyleBox["local variable", FontColor->RGBColor[1, 0, 0]], " inside a ", StyleBox["Module", FontWeight->"Bold"], ". Nothing you do to local ", StyleBox["Module", FontWeight->"Bold"], " variables will cause reevaluating, because it is part of the definition of \ Module that values of local variables do not survive from one invocation to \ the next." }], "Text", CellChangeTimes->{{3.620446810109128*^9, 3.620446821695724*^9}, 3.6204469345609627`*^9, {3.620447015863055*^9, 3.620447038086142*^9}, { 3.620492857099554*^9, 3.620492874881255*^9}}, TextJustification->1.], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "temp", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"temp", "=", "n"}], ";", "\[IndentingNewLine]", RowBox[{"temp", "=", RowBox[{"temp", "^", "3"}]}], ";", "\[IndentingNewLine]", "temp"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellChangeTimes->{{3.6204461044006157`*^9, 3.6204461138091908`*^9}, { 3.620446831071809*^9, 3.6204468602325172`*^9}, 3.620446891662198*^9, { 3.620446923530517*^9, 3.620446926729505*^9}, 3.651893020368326*^9}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]], Cell[CellGroupData[{ Cell["Solution 4", "Subsubsection", CellDingbat->"\[SadSmiley]", CellChangeTimes->{{3.620458862139105*^9, 3.620458865490685*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", RowBox[{"x", "^", "2"}]}], ";", "\[IndentingNewLine]", RowBox[{"f", "[", "n", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.620458891774808*^9, 3.620458927888977*^9}}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]], Cell[CellGroupData[{ Cell["Solution 5", "Subsubsection", CellDingbat->"\[HappySmiley]", CellChangeTimes->{{3.620458977077963*^9, 3.620458980165422*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"Module", "[", RowBox[{ RowBox[{"{", "g", "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"g", "[", "x_", "]"}], ":=", RowBox[{"x", "^", "2"}]}], ";", "\[IndentingNewLine]", RowBox[{"g", "[", "n", "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.620458891774808*^9, 3.620458927888977*^9}, { 3.620459001510879*^9, 3.6204590114858723`*^9}, {3.62045960379865*^9, 3.620459625533647*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell["\<\ The function g is now a local variable, so it does not cause any extra \ reevaluations. Notice that it is not defined outside of Module[...], so if \ you try to call g[3] say, somewhere below, the function g will not be \ recognized.\ \>", "Text", CellChangeTimes->{{3.620459656861783*^9, 3.620459760207458*^9}, { 3.620460013707011*^9, 3.6204600167775707`*^9}, {3.620460362336363*^9, 3.620460362735216*^9}, {3.620492963306772*^9, 3.620492968048561*^9}, { 3.620493032499256*^9, 3.6204930396494102`*^9}}, TextJustification->1.], Cell[BoxData[ RowBox[{"g", "[", "3", "]"}]], "Input", CellChangeTimes->{{3.62049297112847*^9, 3.6204929729784718`*^9}}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]], Cell[CellGroupData[{ Cell["Solution 6", "Subsubsection", CellDingbat->"\[HappySmiley]", CellChangeTimes->{{3.620459492669979*^9, 3.6204595236847553`*^9}}], Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", RowBox[{"x", "^", "2"}]}], ";", "\[IndentingNewLine]", RowBox[{"f", "[", "n", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}], ",", " ", RowBox[{"TrackedSymbols", "\[RuleDelayed]", RowBox[{"{", "n", "}"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.620459771497446*^9, 3.620459798920413*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell["\<\ We can keep the function f global, without causing any reevaluations of \ Manipulate, if we explicitly indicate that the only variable whose values we \ should keep track of is the parameter n (by default, Manipulate[...] tracks \ both f and n). The example above reevaluates only when n changes its value as \ a result of moving the slider.\ \>", "Text", CellChangeTimes->{{3.620459539459815*^9, 3.620459559828752*^9}, { 3.6204598124242563`*^9, 3.6204599791217127`*^9}}, TextJustification->1.] }, Open ]], Cell[CellGroupData[{ Cell["Solution 7", "Subsubsection", CellDingbat->"\[SadSmiley]", CellChangeTimes->{{3.620459492669979*^9, 3.6204595236847553`*^9}, { 3.651877570569934*^9, 3.651877571017352*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"h", "[", "x_", "]"}], ":=", RowBox[{"x", "^", "2"}]}], "\[IndentingNewLine]", RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"h", "[", "n", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}]}], "]"}]}], "Input", CellChangeTimes->{{3.620459771497446*^9, 3.620459798920413*^9}, { 3.6518776148410273`*^9, 3.651877648208106*^9}, {3.651877807999195*^9, 3.651877812909697*^9}, {3.651884861280748*^9, 3.651884895353051*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell[TextData[{ "We can also define the function h(x)=x^2 globally, before Manipulate[..]. \ At first glance, it looks like everything works well and without causing any \ reevaluations of Manipulate. \n", StyleBox["The downfall is that the definition of the function h (which is \ called later in the body of Manipulate) is not saved together with the output \ of Manipulate.", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0.6, 0.4, 0.2]], "To see this, open a new ", StyleBox["Mathematica", FontSlant->"Italic"], " notebook, and set \[OpenCurlyDoubleQuote]Evaluation->Notebook\ \[CloseCurlyQuote]s Default Context\[CloseCurlyDoubleQuote] to \ \[OpenCurlyDoubleQuote]Unique to this notebook\[CloseCurlyDoubleQuote]. Then \ copy ONLY the output of Manipulate (that is, ONLY the interactive model, \ absolutely NO code) in the new notebook. Try changing the slider. What do you \ notice?" }], "Text", CellChangeTimes->{{3.620459539459815*^9, 3.620459559828752*^9}, { 3.6204598124242563`*^9, 3.6204599791217127`*^9}, {3.65188490076551*^9, 3.651885022864422*^9}, {3.65188508672822*^9, 3.651885252730834*^9}, { 3.6518853651070547`*^9, 3.651885424635213*^9}, {3.651885531318499*^9, 3.6518855373676443`*^9}, {3.651885713699656*^9, 3.6518857552989073`*^9}, { 3.651886310872673*^9, 3.651886312975297*^9}, {3.651886556304495*^9, 3.651886556880157*^9}, {3.651886612230092*^9, 3.65188667690272*^9}, { 3.651923385990995*^9, 3.651923421970903*^9}, 3.6960511643945093`*^9}, TextJustification->1.] }, Open ]], Cell[CellGroupData[{ Cell["Solution 8", "Subsubsection", CellDingbat->"\[HappySmiley]", CellChangeTimes->{{3.620459492669979*^9, 3.6204595236847553`*^9}, { 3.651877570569934*^9, 3.651877571017352*^9}, {3.651885264112996*^9, 3.651885264519648*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"k", "[", "x_", "]"}], ":=", RowBox[{"x", "^", "2"}]}], "\[IndentingNewLine]", RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "[", "n", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "1", ",", "4"}], "}"}], ",", RowBox[{"SaveDefinitions", "\[Rule]", "True"}]}], "]"}]}], "Input", CellChangeTimes->{{3.620459771497446*^9, 3.620459798920413*^9}, { 3.6518776148410273`*^9, 3.651877648208106*^9}, {3.651877807999195*^9, 3.651877812909697*^9}, {3.651884861280748*^9, 3.65188486365689*^9}, { 3.696052316236649*^9, 3.6960523205460033`*^9}}, Background->RGBColor[0.87, 0.94, 1]], Cell[TextData[{ "The option \[OpenCurlyDoubleQuote]", StyleBox["SaveDefinitions", FontWeight->"Bold"], "\[Rule]", StyleBox["True", FontWeight->"Bold"], "\[CloseCurlyDoubleQuote] forces any function definitions used by Manipulate \ to be saved with the output. The output can be copied and directly run in a \ new notebook. Try it!" }], "Text", CellChangeTimes->{{3.620459539459815*^9, 3.620459559828752*^9}, { 3.6204598124242563`*^9, 3.6204599791217127`*^9}, {3.651885590436352*^9, 3.6518856391239777`*^9}, {3.6518856842390833`*^9, 3.651885698368929*^9}, { 3.65192346449772*^9, 3.6519234667514067`*^9}, {3.654490784129632*^9, 3.6544907856689653`*^9}}, TextJustification->1.] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Working with random elements inside Manipulate", "Section", CellChangeTimes->{{3.621175941801478*^9, 3.6211759581244907`*^9}, { 3.621179448673835*^9, 3.621179455673559*^9}, {3.696055361259347*^9, 3.69605536408212*^9}}], Cell[TextData[{ StyleBox["How about generating random elements inside the body of ", Background->RGBColor[1, 0.85, 0.85]], StyleBox["Manipulate[ ...]", FontWeight->"Bold", Background->RGBColor[1, 0.85, 0.85]], StyleBox["?", Background->RGBColor[1, 0.85, 0.85]], " Should the code below reevaluate itself as fast as possible, each time \ generating a new random integer?" }], "Text", CellChangeTimes->{{3.621179819232498*^9, 3.6211798678393927`*^9}, { 3.6214597140119133`*^9, 3.621459758904436*^9}}, FontSize->16], Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"x", " ", "=", RowBox[{"RandomInteger", "[", "n", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{"10", ",", "100"}], "}"}]}], "}"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellChangeTimes->{{3.621175967657094*^9, 3.6211759710325403`*^9}, { 3.621176296891788*^9, 3.621176451471263*^9}, {3.621176578999605*^9, 3.6211765810677557`*^9}, {3.6211783204439697`*^9, 3.6211783220668993`*^9}, { 3.621178361634738*^9, 3.6211784704234858`*^9}, {3.6211785175603313`*^9, 3.6211785210230103`*^9}, {3.69605543397351*^9, 3.696055464653009*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[TextData[{ "Every time you evaluate ", StyleBox["RandomReal[...]", FontWeight->"Bold"], " or ", StyleBox["RandomInteger[...]", FontWeight->"Bold"], " or ", StyleBox["RandomGraph[...]", FontWeight->"Bold"], ", you get a different answer, and you might think that an assignment like \ ", StyleBox["x=RandomReal[...]", FontWeight->"Bold"], " inside ", StyleBox["Manipulate[...]", FontWeight->"Bold"], " should therefore constantly update itself as fast as possible. But this \ would normally not be useful, and would in fact have negative consequences \ for a number of algorithms that use randomness internally. For this reason, \ these functions are not \"", StyleBox["ticklish", FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], "\", in the sense that they do not trigger updates. If you want to see \ actually new random numbers, you have to use Refresh to specify how \ frequently you want the output updated. " }], "Text", CellChangeTimes->{{3.621176831728299*^9, 3.621176855505334*^9}, 3.6211769105862217`*^9, {3.6211769840836573`*^9, 3.621176992916872*^9}, { 3.62117731140322*^9, 3.621177392721541*^9}, {3.621178243427885*^9, 3.621178286569848*^9}}, TextJustification->1.], Cell[CellGroupData[{ Cell["\<\ Example 2. Make an interactive model that draws a random directed graph with \ n vertices, for n between 4 and 7.\ \>", "Subsection", CellDingbat->"\[FilledSquare]", CellChangeTimes->{{3.6204459738089523`*^9, 3.6204460536405697`*^9}, { 3.6204462152671022`*^9, 3.6204462159137497`*^9}, {3.620446287434054*^9, 3.6204463030498953`*^9}, 3.6204463496461906`*^9, {3.620447091230641*^9, 3.620447096110468*^9}, 3.620447294151079*^9, {3.6205028594316874`*^9, 3.6205028623514967`*^9}, {3.6514662637081203`*^9, 3.651466314540477*^9}}], Cell[BoxData[ RowBox[{ StyleBox["Manipulate", Background->RGBColor[1, 1, 0.85]], StyleBox["[", Background->RGBColor[1, 1, 0.85]], "\[IndentingNewLine]", RowBox[{ RowBox[{"RandomGraph", "[", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "5"}], "}"}], ",", RowBox[{"GraphStyle", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"ImageSize", "\[Rule]", "Medium"}]}], "]"}], ",", " ", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{"4", ",", "5", ",", "6", ",", "7"}], "}"}]}], "}"}]}], StyleBox["]", Background->RGBColor[1, 1, 0.85]]}]], "Input", CellChangeTimes->CompressedData[" 1:eJxTTMoPSmViYGAQBmIQLVKzZvqPb68c392KWgSilxQ9XAOiI3b4rwXRk7zM Z/0E0m+lTy8A0bNKtdf/AtK/TnwG03q6BdtAdEbgDjCddffq6t9A2uLc4g0g 2sGU/RSIFp4tewZEB7bmXADRacaPL4HoP7/3PAPRUx7UvQTRlVFX34LoMxtu gulTogc+gWi+05O+gOi5n41X/QHSMmcN14LooAt+7aHfXzmq9It1gGifY9GV 80xeO65IKwPTHnPy6kB0evBMMH0tvCtpEZD+9ntuMog2Mn9psxhIPz1yyA5E a3jdyAPRH4t/lYJog42fG0C0Yy9/K4gGAKBDvcA= "], FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell["\<\ If we do not want the graphics to rescale every time we generate a new graph, \ we can set the dimensions of the graphical object ImageSize -> {1000, 300}. \ Or we can set the dimensions of the window displayed by Manipulate[..] using \ ContentSize -> {1000, 300}.\ \>", "Text", CellChangeTimes->{{3.6514663311924047`*^9, 3.651466440249024*^9}, { 3.65147264076101*^9, 3.651472734637772*^9}, {3.651472822908345*^9, 3.651472854881692*^9}, 3.695541980417535*^9}], Cell[BoxData[ RowBox[{ StyleBox["Manipulate", Background->RGBColor[1, 1, 0.85]], StyleBox["[", Background->RGBColor[1, 1, 0.85]], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphPlot", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"RandomInteger", "[", "]"}], ",", RowBox[{"{", "n", "}"}], ",", RowBox[{"{", "n", "}"}]}], "]"}], ",", " ", RowBox[{"VertexLabeling", "\[Rule]", "True"}], ",", " ", RowBox[{"DirectedEdges", "\[Rule]", "True"}], ",", " ", RowBox[{"ImageSize", "\[Rule]", RowBox[{"{", RowBox[{"1000", ",", "300"}], "}"}]}]}], "]"}], ",", " ", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "4", ",", "7"}], "}"}]}], StyleBox["]", Background->RGBColor[1, 1, 0.85]]}]], "Input", CellChangeTimes->{{3.6191448933901463`*^9, 3.619144978839225*^9}, { 3.619145063045244*^9, 3.619145066491253*^9}, {3.619146961727853*^9, 3.619147014347159*^9}, {3.6191491773581057`*^9, 3.6191491836182833`*^9}, { 3.619149235505515*^9, 3.6191492377599373`*^9}, {3.619151198683278*^9, 3.619151237118923*^9}, {3.6191514402252502`*^9, 3.61915145692518*^9}, { 3.619151491391274*^9, 3.619151511100024*^9}, {3.61915166990576*^9, 3.6191516919649143`*^9}, {3.619151726667294*^9, 3.6191517268028316`*^9}, { 3.61915176600266*^9, 3.619151780587287*^9}, {3.619153233623488*^9, 3.619153257556288*^9}, {3.6193352264629297`*^9, 3.619335232704973*^9}, { 3.651466186867956*^9, 3.6514661877000313`*^9}, {3.651466418549283*^9, 3.651466418900033*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell[BoxData[ RowBox[{ StyleBox["Manipulate", Background->RGBColor[1, 1, 0.85]], StyleBox["[", Background->RGBColor[1, 1, 0.85]], "\[IndentingNewLine]", RowBox[{ RowBox[{"RandomGraph", "[", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "5"}], "}"}], ",", RowBox[{"GraphStyle", "\[Rule]", "\"\\""}], ",", " ", RowBox[{"ImageSize", "\[Rule]", "Medium"}]}], "]"}], ",", " ", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{"4", ",", "5", ",", "6", ",", "7"}], "}"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"ContentSize", "\[Rule]", RowBox[{"{", RowBox[{"1000", ",", "500"}], "}"}]}]}], StyleBox["]", Background->RGBColor[1, 1, 0.85]]}]], "Input", CellChangeTimes->{{3.6191448933901463`*^9, 3.619144978839225*^9}, { 3.619145063045244*^9, 3.619145066491253*^9}, {3.619146961727853*^9, 3.619147014347159*^9}, {3.6191491773581057`*^9, 3.6191491836182833`*^9}, { 3.619149235505515*^9, 3.6191492377599373`*^9}, {3.619151198683278*^9, 3.619151237118923*^9}, {3.6191514402252502`*^9, 3.61915145692518*^9}, { 3.619151491391274*^9, 3.619151511100024*^9}, {3.61915166990576*^9, 3.6191516919649143`*^9}, {3.619151726667294*^9, 3.6191517268028316`*^9}, { 3.61915176600266*^9, 3.619151780587287*^9}, {3.619153233623488*^9, 3.619153257556288*^9}, {3.6193352264629297`*^9, 3.619335232704973*^9}, { 3.651466186867956*^9, 3.6514661877000313`*^9}, {3.651466418549283*^9, 3.651466418900033*^9}, {3.65147274318712*^9, 3.651472785203713*^9}, { 3.651476552822178*^9, 3.651476589118026*^9}, {3.651476625863173*^9, 3.65147666212101*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["How to manipulate several functions of several parameters", "Section", CellChangeTimes->{{3.619155011716567*^9, 3.6191550578253527`*^9}, { 3.6508861867204237`*^9, 3.6508861894549294`*^9}, {3.6508862984440413`*^9, 3.650886302346953*^9}}], Cell[CellGroupData[{ Cell["\<\ Example 3. Make an interactive model that draws the graphs of the functions \ cos(mx) and sin(nx), where m is a continuous parameter in the interval [1,2], \ and n a discrete parameter in the set {4,5,6,7}.\ \>", "Subsection", CellDingbat->"\[FilledSquare]", CellChangeTimes->{{3.6204459738089523`*^9, 3.6204460536405697`*^9}, { 3.6204462152671022`*^9, 3.6204462159137497`*^9}, {3.620446287434054*^9, 3.6204463030498953`*^9}, 3.6204463496461906`*^9, {3.620447091230641*^9, 3.620447096110468*^9}, 3.620447294151079*^9, {3.6205028594316874`*^9, 3.6205028623514967`*^9}, {3.6514662637081203`*^9, 3.651466314540477*^9}, { 3.651466525089361*^9, 3.6514666225484324`*^9}, {3.696056313216996*^9, 3.696056313751626*^9}, {3.696059653228888*^9, 3.696059653762322*^9}}], Cell[BoxData[ RowBox[{ StyleBox["Manipulate", Background->RGBColor[1, 1, 0.85]], StyleBox["[", Background->RGBColor[1, 1, 0.85]], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["GraphicsRow", FontColor->GrayLevel[0], Background->RGBColor[1, 0.9, 1]], StyleBox["[", FontColor->RGBColor[1, 0, 1]], RowBox[{ StyleBox["{", FontColor->RGBColor[1, 0, 1]], "\[IndentingNewLine]", RowBox[{ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Cos", "[", RowBox[{"m", "*", "x"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", RowBox[{"2", "*", "Pi"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Sin", "[", RowBox[{"n", "*", "x"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", RowBox[{"2", "*", "Pi"}]}], "}"}]}], "]"}]}], " ", StyleBox["}", FontColor->RGBColor[1, 0, 1]]}], StyleBox["]", FontColor->RGBColor[1, 0, 1]]}], ",", " ", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", RowBox[{"{", RowBox[{"4", ",", "5", ",", "6", ",", " ", "7"}], "}"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"m", ",", " ", "1", ",", "2"}], "}"}]}], "\[IndentingNewLine]", StyleBox["]", Background->RGBColor[1, 1, 0.85]]}]], "Input", CellChangeTimes->{{3.619153007774909*^9, 3.6191530925713997`*^9}, { 3.6191534174317093`*^9, 3.6191534468962383`*^9}, {3.61915360319213*^9, 3.619153622165175*^9}, 3.61915365517513*^9, {3.619153712931726*^9, 3.619153722441154*^9}, {3.619153794878572*^9, 3.619153810489418*^9}, { 3.6191542251307793`*^9, 3.619154232614328*^9}, {3.619154318011808*^9, 3.619154322410777*^9}, {3.619154420469096*^9, 3.619154453799613*^9}, { 3.619154525695928*^9, 3.619154582046821*^9}, {3.619154660564479*^9, 3.6191547442026587`*^9}, {3.619154796840465*^9, 3.619154803735847*^9}, { 3.6191548759896383`*^9, 3.619154879168077*^9}, {3.619154911898974*^9, 3.6191549419832783`*^9}, {3.61915536793128*^9, 3.619155406356728*^9}, { 3.619332588419709*^9, 3.619332682709671*^9}, {3.619332804939764*^9, 3.6193328068240013`*^9}, {3.6193329007436037`*^9, 3.6193329023568087`*^9}, {3.619333685776278*^9, 3.619333718373911*^9}, { 3.6193354253285933`*^9, 3.619335559711834*^9}, {3.6193356330181513`*^9, 3.619335651004884*^9}, {3.6508860654167547`*^9, 3.6508861022253637`*^9}, { 3.650886132243082*^9, 3.650886168480792*^9}, {3.650886223693612*^9, 3.650886268827368*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]], Cell["It is possible to have correlated sliders.", "Text", CellChangeTimes->{{3.6514723619868097`*^9, 3.651472381429888*^9}, 3.6514728794692297`*^9, 3.6514730782552013`*^9}], Cell[BoxData[ RowBox[{ StyleBox["Manipulate", Background->RGBColor[1, 1, 0.85]], StyleBox["[", Background->RGBColor[1, 1, 0.85]], "\[IndentingNewLine]", RowBox[{ RowBox[{"Column", StyleBox["[", FontColor->RGBColor[1, 0, 1]], RowBox[{ StyleBox["{", FontColor->RGBColor[1, 0, 1]], RowBox[{ StyleBox["\"\\"", FontColor->RGBColor[1, 0, 1]], StyleBox[",", FontColor->RGBColor[1, 0, 1]], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Cos", "[", RowBox[{"m", "*", "x"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", RowBox[{"2", "*", "Pi"}]}], "}"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Sin", "[", RowBox[{"n", "*", "x"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", RowBox[{"2", "*", "Pi"}]}], "}"}]}], "]"}]}], " ", StyleBox["}", FontColor->RGBColor[1, 0, 1]]}], StyleBox["]", FontColor->RGBColor[1, 0, 1]]}], ",", " ", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"n", ",", "m", ",", RowBox[{"2", "*", "m"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"m", ",", " ", "1", ",", "2"}], "}"}]}], "\[IndentingNewLine]", StyleBox["]", Background->RGBColor[1, 1, 0.85]]}]], "Input", CellChangeTimes->{{3.619153007774909*^9, 3.6191530925713997`*^9}, { 3.6191534174317093`*^9, 3.6191534468962383`*^9}, {3.61915360319213*^9, 3.619153622165175*^9}, 3.61915365517513*^9, {3.619153712931726*^9, 3.619153722441154*^9}, {3.619153794878572*^9, 3.619153810489418*^9}, { 3.6191542251307793`*^9, 3.619154232614328*^9}, {3.619154318011808*^9, 3.619154322410777*^9}, {3.619154420469096*^9, 3.619154453799613*^9}, { 3.619154525695928*^9, 3.619154582046821*^9}, {3.619154660564479*^9, 3.6191547442026587`*^9}, {3.619154796840465*^9, 3.619154803735847*^9}, { 3.6191548759896383`*^9, 3.619154879168077*^9}, {3.619154911898974*^9, 3.6191549419832783`*^9}, {3.61915536793128*^9, 3.619155406356728*^9}, { 3.619332588419709*^9, 3.619332682709671*^9}, {3.619332804939764*^9, 3.6193328068240013`*^9}, {3.6193329007436037`*^9, 3.6193329023568087`*^9}, {3.619333685776278*^9, 3.619333718373911*^9}, { 3.6193354253285933`*^9, 3.619335559711834*^9}, {3.6193356330181513`*^9, 3.619335651004884*^9}, {3.6508860654167547`*^9, 3.6508861022253637`*^9}, { 3.650886132243082*^9, 3.650886168480792*^9}, {3.650886223693612*^9, 3.650886268827368*^9}, {3.651472395542636*^9, 3.651472431507859*^9}, { 3.651472883104754*^9, 3.651472959925159*^9}, {3.651478476414166*^9, 3.651478477870191*^9}, {3.651478795008175*^9, 3.6514788950222063`*^9}}, FontSize->14, Background->RGBColor[0.87, 0.94, 1]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Exercises:", "Section", CellChangeTimes->{{3.696052413385202*^9, 3.696052431293272*^9}}], Cell[CellGroupData[{ Cell["\<\ Exercise 1. Make an interactive model that reads the value of two variables, \ total and sum, represented by two different controls, and outputs their sum, \ total+sum. Does the example below do that? \ \>", "Subsection", CellDingbat->"\[FilledSquare]", CellChangeTimes->{{3.620447133268231*^9, 3.620447196828288*^9}, { 3.620447614477296*^9, 3.6204476416878357`*^9}, 3.6204495418065853`*^9, { 3.620493148092608*^9, 3.6204931514192123`*^9}, {3.651886868820175*^9, 3.651886873204561*^9}}, FontSize->18], Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", " ", RowBox[{ RowBox[{ RowBox[{"total", "=", RowBox[{"total", "+", "step"}]}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"step", ",", "total"}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"total", ",", "0"}], "}"}], ",", RowBox[{"-", "1000"}], ",", "1000", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"step", ",", "0"}], "}"}], ",", RowBox[{"-", "10"}], ",", "10", ",", "1"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"FrameLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input", CellChangeTimes->{{3.6204450441644983`*^9, 3.620445044165217*^9}, { 3.620447495199263*^9, 3.6204475027974863`*^9}, {3.620447540852353*^9, 3.620447545875905*^9}, {3.620447589701573*^9, 3.620447597363188*^9}, { 3.620458568238985*^9, 3.620458595142166*^9}}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Exercise 2. A way to compute the sum of the first m positive integers in ", StyleBox["Mathematica", FontSlant->"Italic"], " is to do a For loop, like the one written below. Turn the code below into \ an interactive model where m will be allowed to take any values in the set \ {10, 20, 30, 40, 50}. " }], "Subsection", CellDingbat->"\[FilledSquare]", CellChangeTimes->{{3.620447757692485*^9, 3.620447762500182*^9}, { 3.620448651813036*^9, 3.620448716410104*^9}, {3.620448773793989*^9, 3.620448999525469*^9}, {3.6204490558175097`*^9, 3.6204490817380733`*^9}, { 3.651886879161338*^9, 3.651886883281176*^9}, {3.6518878250903788`*^9, 3.651887852115736*^9}, {3.6518938447716618`*^9, 3.65189385958366*^9}}, TextJustification->1., FontSize->18], Cell[BoxData[{ RowBox[{ RowBox[{"m", "=", "5"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"s", "=", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", "m"}], ",", RowBox[{"i", "++"}], ",", " ", RowBox[{"s", "=", RowBox[{"s", "+", "i"}]}]}], "]"}], ";"}], "\[IndentingNewLine]", "s"}], "Input", CellChangeTimes->{{3.620448746142027*^9, 3.620448769506248*^9}}, Background->RGBColor[0.87, 0.94, 1]] }, Open ]], Cell["\<\ Exercise 3. Do an interactive model using Manipulate[...] that displays the \ pair of numbers x and ax^2+bx+c, where a,b,c are real parameters, and x is a \ randomly generated number, between min and max, x=RandomReal[{min,max}]. The \ model will have 5 controls that can be set by the user: a,b,c,min, max (a, \ b, c are real numbers between 1 and 10, min is an integer number in the set \ {2,3,4}, and max is also an integer number in the set {5,6,7}).\ \>", "Subsection", CellDingbat->"\[FilledSquare]", CellChangeTimes->{{3.620447757692485*^9, 3.620447762500182*^9}, { 3.620448651813036*^9, 3.620448716410104*^9}, {3.620448773793989*^9, 3.620448999525469*^9}, {3.6204490558175097`*^9, 3.6204490817380733`*^9}, { 3.651886879161338*^9, 3.651886883281176*^9}, {3.6518878250903788`*^9, 3.651887852115736*^9}, {3.6518938447716618`*^9, 3.65189385958366*^9}, { 3.696054608714691*^9, 3.696054890847954*^9}, {3.6960550285481577`*^9, 3.696055104620757*^9}, {3.696055869247199*^9, 3.696056085269106*^9}}, TextJustification->1., FontSize->18] }, Open ]] }, Open ]] }, WindowSize->{954, 574}, WindowMargins->{{Automatic, 79}, {Automatic, 2}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, FrontEndVersion->"11.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (September \ 21, 2016)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 354, 5, 92, "Title"], Cell[CellGroupData[{ Cell[959, 31, 199, 3, 64, "Section"], Cell[1161, 36, 721, 11, 115, "Text"], Cell[CellGroupData[{ Cell[1907, 51, 1061, 21, 131, "Subsubsection"], Cell[2971, 74, 1274, 27, 167, "Text"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[4294, 107, 206, 3, 64, "Section"], Cell[CellGroupData[{ Cell[4525, 114, 475, 9, 44, "Subsection"], Cell[CellGroupData[{ Cell[5025, 127, 183, 3, 35, "Subsubsection"], Cell[5211, 132, 380, 9, 48, "Input"], Cell[5594, 143, 691, 11, 87, "Text"], Cell[6288, 156, 291, 5, 30, "Text"], Cell[6582, 163, 389, 11, 48, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7008, 179, 398, 5, 35, "Subsubsection"], Cell[7409, 186, 385, 6, 49, "Text"], Cell[7797, 194, 583, 9, 49, "Text"], Cell[8383, 205, 515, 10, 48, "Input"], Cell[8901, 217, 436, 9, 48, "Input"], Cell[9340, 228, 304, 6, 49, "Text"], Cell[9647, 236, 496, 12, 48, "Input"], Cell[10146, 250, 236, 5, 30, "Text"], Cell[10385, 257, 660, 15, 48, "Input"], Cell[11048, 274, 394, 6, 49, "Text"], Cell[11445, 282, 245, 6, 48, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11727, 293, 497, 9, 35, "Subsubsection"], Cell[12227, 304, 1481, 28, 125, "Text"], Cell[13711, 334, 810, 18, 48, "Input"], Cell[14524, 354, 916, 19, 91, "Input"], Cell[15443, 375, 813, 18, 48, "Input"] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[16317, 400, 285, 3, 64, "Section"], Cell[CellGroupData[{ Cell[16627, 407, 475, 9, 44, "Subsection"], Cell[CellGroupData[{ Cell[17127, 420, 130, 2, 35, "Subsubsection"], Cell[17260, 424, 643, 14, 154, "Input"], Cell[17906, 440, 722, 14, 68, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[18665, 459, 135, 2, 35, "Subsubsection"], Cell[18803, 463, 771, 20, 68, "Text"], Cell[19577, 485, 740, 17, 154, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[20354, 507, 131, 2, 35, "Subsubsection"], Cell[20488, 511, 456, 11, 112, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[20981, 527, 133, 2, 35, "Subsubsection"], Cell[21117, 531, 650, 16, 112, "Input"], Cell[21770, 549, 544, 10, 49, "Text"], Cell[22317, 561, 159, 3, 48, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[22513, 569, 135, 2, 35, "Subsubsection"], Cell[22651, 573, 546, 13, 112, "Input"], Cell[23200, 588, 508, 9, 68, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[23745, 602, 182, 3, 35, "Subsubsection"], Cell[23930, 607, 575, 12, 112, "Input"], Cell[24508, 621, 1540, 28, 125, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[26085, 654, 233, 4, 35, "Subsubsection"], Cell[26321, 660, 682, 14, 112, "Input"], Cell[27006, 676, 695, 16, 49, "Text"] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[27762, 699, 230, 3, 64, "Section"], Cell[27995, 704, 528, 13, 55, "Text"], Cell[28526, 719, 754, 16, 117, "Input"], Cell[29283, 737, 1223, 32, 106, "Text"], Cell[CellGroupData[{ Cell[30531, 773, 550, 9, 69, "Subsection"], Cell[31084, 784, 1092, 29, 95, "Input"], Cell[32179, 815, 477, 8, 49, "Text"], Cell[32659, 825, 1618, 36, 117, "Input"], Cell[34280, 863, 1733, 38, 117, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[36062, 907, 248, 3, 64, "Section"], Cell[CellGroupData[{ Cell[36335, 914, 791, 12, 69, "Subsection"], Cell[37129, 928, 2675, 63, 183, "Input"], Cell[39807, 993, 178, 2, 30, "Text"], Cell[39988, 997, 2889, 64, 183, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[42926, 1067, 95, 1, 64, "Section"], Cell[CellGroupData[{ Cell[43046, 1072, 523, 10, 65, "Subsection"], Cell[43572, 1084, 1014, 25, 133, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[44623, 1114, 773, 15, 88, "Subsection"], Cell[45399, 1131, 529, 15, 112, "Input"] }, Open ]], Cell[45943, 1149, 1064, 17, 111, "Subsection"] }, Open ]] }, Open ]] } ] *)