List[Null, Null, Null, Null, Null, Null, Null, Notebook[List[Cell[CellGroupData[List[Cell["Exercise 3", "Title"], Cell[CellGroupData[List[Cell["while-statements", "Section"], Cell[TextData[List["Write a class that calculates the sum: ", Cell[BoxData[FormBox[FractionBox["1", RowBox[List["1", "*", "1"]]], TraditionalForm]], Rule[FontSize, 14]], "-", StyleBox[" ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["2", "*", "2"]]], TraditionalForm]], Rule[FontSize, 14]], StyleBox[" + ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["3", "*", "3"]]], TraditionalForm]], Rule[FontSize, 14]], StyleBox[" - ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["4", "*", "4"]]], TraditionalForm]], Rule[FontSize, 14]], " ", StyleBox["+ ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["5", "*", "5"]]], TraditionalForm]], Rule[FontSize, 14]], StyleBox[" - ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["6", "*", "6"]]], TraditionalForm]], Rule[FontSize, 14]], StyleBox[" ... ", Rule[FontSize, 14]], "\nFollow the algorithm:\n\t\t1. Initialize the sum to 0 and the first term to 1.\n\t\t2. If the absolut value of next term >= 0.000001 do the next two steps:\n\t\t\t2.1 Add next term to the sum.\n\t\t\t2.2 Calculate a new next term.\t\t\n\t\t\t"]], "Text"], Cell["", "ModelicaInput"], Cell[CellGroupData[List[Cell["Tip", "Subsection"], Cell["Every term in the sum is on the form 1/(k*k), where k increaces by one for each step. Set a variable to keep track of if the next term is negative or positive. When the program is run the sum will be 0.82247.\t", "Text"]], Closed]], Cell[CellGroupData[List[Cell["Answer", "Subsection"], Cell[CellGroupData[List[Cell["SumCalculation", "Subsubsection"], Cell[TextData[List["If the operator ", StyleBox["abs", Rule[FontFamily, "Courier"]], " is used outside a when clause, state events are triggered. If this is not desired, the ", StyleBox["noEvent", Rule[FontFamily, "Courier"]], " function can be applied to it."]], "Text"], Cell["class SumCalculation\n  constant Real e = 0.000001;\n  Real sum(start = 0);\n  Real next(start = 1.0);\n  Integer k(start = 1);\t\t\t\t\n  Integer posneg(start = 1);\t\t// if the sign in front of the term is + or -\nalgorithm\n  while noEvent(abs(next)) >= e loop  \n    sum := sum + next;\t\t\t\t// Add the sum to the next term\n    k := k + 1;\t\t\t\t\t\t// calculate a new next\n    posneg := - posneg;\n    next := posneg/(k*k);\n  end while;\nend SumCalculation;", "ModelicaInput"]], Closed]], Cell[CellGroupData[List[Cell["Simulation of SumCalculation", "Subsubsection"], Cell["simulate( SumCalculation );", "ModelicaInput"], Cell[BoxData["\"<SimulationData: \\!\\(SumCalculation\\) : 2004-1-30 14:55:5.2037180 : \\!\\({0.`, 1.`}\\) : 502 data points : 1 events : 7 variables>\\n\\!\\({\\*TagBox[\\\"\[UnderBracket]derdummy\\\", HoldForm], \\*TagBox[\\\"\[UnderBracket]dummy\\\", HoldForm], \\*TagBox[\\\"e\\\", HoldForm], \\*TagBox[\\\"k\\\", HoldForm], \\*TagBox[\\\"next\\\", HoldForm], \\*TagBox[\\\"posneg\\\", HoldForm], \\*TagBox[\\\"sum\\\", HoldForm]}\\)\""], "Output"], Cell[TextData[List["When the program is run the sum will be 0.82247 and it will calculate the sum of: \t", Cell[BoxData[FormBox[FractionBox["1", RowBox[List["1", "*", "1"]]], TraditionalForm]], Rule[FontSize, 14]], "-", StyleBox[" ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["2", "*", "2"]]], TraditionalForm]], Rule[FontSize, 14]], StyleBox[" + ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["3", "*", "3"]]], TraditionalForm]], Rule[FontSize, 14]], StyleBox[" - ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["4", "*", "4"]]], TraditionalForm]], Rule[FontSize, 14]], " ", StyleBox["+ ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["5", "*", "5"]]], TraditionalForm]], Rule[FontSize, 14]], StyleBox["  ... - ", Rule[FontSize, 14]], Cell[BoxData[FormBox[FractionBox["1", RowBox[List["1001", "*", "1001"]]], TraditionalForm]], Rule[FontSize, 14]]]], "Text"], Cell[BoxData[RowBox[List["{", RowBox[List[RowBox[List["sum", "[", "1", "]"]], ",", " ", RowBox[List["next", "[", "1", "]"]], ",", " ", RowBox[List["posneg", "[", "1", "]"]], ",", " ", RowBox[List["k", "[", "1", "]"]]]], "}"]]], "Input"]], Closed]]], Closed]]], Open]]], Open]]], Rule[FrontEndVersion, "5.1 for Microsoft Windows"], Rule[ScreenRectangle, List[List[0, 1280], List[0, 951]]], Rule[WindowSize, List[728, 900]], Rule[WindowMargins, List[List[1, Automatic], List[Automatic, 1]]], Rule[StyleDefinitions, "MathModelica.nb"]], Null, Null, Null, Null, Null]