List[Null, Null, Null, Null, Null, Null, Null, Notebook[List[Cell[CellGroupData[List[Cell["Exercise 3", "Title"], Cell[CellGroupData[List[Cell["Vector Orthogonality", "Section"], Cell[TextData[List["Write a function, ", StyleBox["ScalarProduct", Rule[FontFamily, "Courier"]], ", that calculates the scalar product of two arbitrary vectors (u1, u2, u3, ..., un) and (v1, v2, v3, ... , vn). The result should be:  u1*v1 + u2*v2 + ... + un*vn."]], "Text"], Cell["", "ModelicaInput"], Cell[TextData[List["\n\nTwo vectors (u1, u2, u3, ..., un) and (v1, v2, v3, ... , vn) are ortogonal if the scalar product: ", Cell[BoxData[FormBox[RowBox[List[UnderoverscriptBox["\[Sum]", RowBox[List["i", "=", "1"]], "n"], RowBox[List["ui", "*", "vi"]]]], TraditionalForm]], Rule[FontSize, 14]], " is equal to 0. \nWrite a class, ", StyleBox["Orthogonal", Rule[FontFamily, "Courier"]], ", that decides if two integer vectors are orthogonal. The vectors must have the same number of elements, but the number of elements should be arbitrary. "]], "Text"], Cell["", "ModelicaInput"], Cell[CellGroupData[List[Cell["Tip", "Subsection"], Cell["Applying the multiplication operator between two vectors gives the scalar product.", "Text"]], Open]], Cell[CellGroupData[List[Cell["Answer", "Subsection"], Cell[CellGroupData[List[Cell["ScalarProduct", "Subsubsection"], Cell["First we check if the vectors are of the same size and if they are we calculate the scalar product.", "Text"], Cell["function ScalarProduct\n  input Integer V1[:];\n  input Integer V2[size(V1,1)];\n  output Integer scalarProduct;\nalgorithm\n  scalarProduct := V1*V2;  \nend ScalarProduct;", "ModelicaInput"]], Closed]], Cell[CellGroupData[List[Cell["Orthogonal", "Subsubsection"], Cell["class Orthogonal\n  Integer V1[:] = {1, 2, 3};\n  Integer V2[:] = {-3, 0, 1};\n  Integer scalarProduct;\n  Boolean orthogonal;\nalgorithm\n  scalarProduct := ScalarProduct(V1, V2);\n  if scalarProduct == 0 then\n    orthogonal := true;\n  end if;  \nend Orthogonal;", "ModelicaInput"]], Closed]], Cell[CellGroupData[List[Cell["Simulation of Orthogonal", "Subsubsection"], Cell["Since the value in the variable orthogonal is 1 the two vectors are orthogonal. ", "Text"], Cell["simulate( Orthogonal );", "ModelicaInput"], Cell[BoxData["\"<SimulationData: \\!\\(Orthogonal\\) : 2004-1-30 15:37:27.3955617 : \\!\\({0.`, 1.`}\\) : 502 data points : 1 events : 10 variables>\\n\\!\\({\\*TagBox[\\\"\[UnderBracket]derdummy\\\", HoldForm], \\*TagBox[\\\"\[UnderBracket]dummy\\\", HoldForm], \\*TagBox[\\\"orthogonal\\\", HoldForm], \\*TagBox[\\\"scalarProduct\\\", HoldForm], \\*TagBox[\\(V1 \[LeftDoubleBracket] \\(\\(1\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(V1 \[LeftDoubleBracket] \\(\\(2\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(V1 \[LeftDoubleBracket] \\(\\(3\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(V2 \[LeftDoubleBracket] \\(\\(1\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(V2 \[LeftDoubleBracket] \\(\\(2\\)\\) \[RightDoubleBracket]\\), HoldForm], \\*TagBox[\\(V2 \[LeftDoubleBracket] \\(\\(3\\)\\) \[RightDoubleBracket]\\), HoldForm]}\\)\""], "Output"], Cell[BoxData[RowBox[List["orthogonal", "[", "0", "]"]]], "Input"]], Closed]]], Closed]]], Open]]], Open]]], Rule[FrontEndVersion, "5.1 for Microsoft Windows"], Rule[ScreenRectangle, List[List[0, 1280], List[0, 951]]], Rule[WindowSize, List[785, 867]], Rule[WindowMargins, List[List[301, Automatic], List[107, Automatic]]], Rule[StyleDefinitions, "MathModelica.nb"]], Null, Null, Null, Null, Null]