List[Null, Null, Null, Null, Null, Null, Null, Notebook[List[Cell[CellGroupData[List[Cell["Exercise 1", "Title"], Cell[CellGroupData[List[Cell["Using Algorithm Sections", "Section"], Cell[TextData[List["Write a function, ", StyleBox["Sum", Rule[FontFamily, "Courier"]], ", which calculates the sum of numbers, in an array of arbitrary size. "]], "Text"], Cell["", "ModelicaInput"], Cell[TextData[List["\nWrite a function, ", StyleBox["Average", Rule[FontFamily, "Courier"]], ", which calculates the average of numbers, in an array of arbitrary size. ", StyleBox["Average", Rule[FontFamily, "Courier"]], " should use make a function call to ", StyleBox["Sum", Rule[FontFamily, "Courier"]], "."]], "Text"], Cell["", "ModelicaInput"], Cell[TextData[List["\nWrite a class, ", StyleBox["LargestAverage", Rule[FontFamily, "Courier"]], ", that has two arrays and calculates the average of each of them. Then it compares the averages and sets a variable to true if the first array is larger than the second and otherwise false.\n"]], "Text"], Cell["", "ModelicaInput"], Cell[CellGroupData[List[Cell["Answer", "Subsection"], Cell[CellGroupData[List[Cell["Sum", "Subsubsection"], Cell["function Sum\n  input Real[:] x;\n  output Real sum;\nalgorithm\n   for i in 1:size(x,1) loop\n    sum := sum + x[i];\n  end for; \nend Sum;", "ModelicaInput"]], Closed]], Cell[CellGroupData[List[Cell["Average", "Subsubsection"], Cell["function Average\n  input Real[:] x;\n  output Real average;\nprotected\n    Real sum;  \nalgorithm\n  average := Sum(x) / size(x,1);\nend Average;", "ModelicaInput"]], Closed]], Cell[CellGroupData[List[Cell["LargestAverage", "Subsubsection"], Cell["class LargestAverage\n  parameter Integer[:] A1 = {1, 2, 3, 4, 5};\n  parameter Integer[:] A2 = {7, 8, 9};\n  Real averageA1, averageA2;\n  Boolean A1Largest(start = false);\nalgorithm\n  averageA1 := Average(A1);\n  averageA2 := Average(A2);\n  if averageA1 > averageA2 then\n    A1Largest := true;\n  else\n    A1Largest := false;\n  end if;\nend LargestAverage; ", "ModelicaInput"]], Closed]], Cell[CellGroupData[List[Cell["Simulation of LargestAverage", "Subsubsection"], Cell["simulate( LargestAverage );", "ModelicaInput"], Cell[BoxData["\"<SimulationData: \\!\\(LargestAverage\\) : 2004-1-30 14:53:41.7529392 : \\!\\({0.`, 1.`}\\) : 502 data points : 1 events : 13 variables>\\n\\!\\({\\*TagBox[\\(A1 \[LeftDoubleBracket] \\(\\(1\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(A1 \[LeftDoubleBracket] \\(\\(2\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(A1 \[LeftDoubleBracket] \\(\\(3\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(A1 \[LeftDoubleBracket] \\(\\(4\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(A1 \[LeftDoubleBracket] \\(\\(5\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\\"A1Largest\\\", HoldForm], \\*TagBox[\\(A2 \[LeftDoubleBracket] \\(\\(1\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(A2 \[LeftDoubleBracket] \\(\\(2\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(A2 \[LeftDoubleBracket] \\(\\(3\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\\"averageA1\\\", HoldForm], \\*TagBox[\\\"averageA2\\\", HoldForm], \\*TagBox[\\\"\[UnderBracket]derdummy\\\", HoldForm], \\*TagBox[\\\"\[UnderBracket]dummy\\\", HoldForm]}\\)\""], "Output"], Cell["When we look at the values in the variables we see that A2 has the largest average (8 ) and therefore the variable A1Largest is false (= 0). ", "Text"], Cell[BoxData[RowBox[List["{", RowBox[List[RowBox[List["A1Largest", "[", "1", "]"]], ",", " ", RowBox[List["averageA1", "[", "1", "]"]], " ", ",", " ", RowBox[List["averageA2", "[", "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[856, 871]], Rule[WindowMargins, List[List[0, Automatic], List[Automatic, 0]]], Rule[StyleDefinitions, "MathModelica.nb"]], Null, Null, Null, Null, Null]