(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 10.1' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 9269, 274] NotebookOptionsPosition[ 8878, 256] NotebookOutlinePosition[ 9222, 271] CellTagsIndexPosition[ 9179, 268] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"A", "=", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"4", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "4", ",", RowBox[{"-", "2"}]}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", RowBox[{"-", "2"}], ",", "4"}], "}"}]}], "}"}], "//", "N"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "=", RowBox[{ RowBox[{"{", RowBox[{"12", ",", RowBox[{"-", "1"}], ",", "5"}], "}"}], "//", "N"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Length", "[", "A", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Epsilon]", "=", "0.1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"maxIter", "=", "100"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"iter", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xOld", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "n"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xNew", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "n"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", "n"}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"sum", " ", "=", " ", "0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "\[LessEqual]", "n"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"j", "<", "i"}], ",", "\[IndentingNewLine]", RowBox[{"sum", "+=", RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xNew", "[", RowBox[{"[", "j", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"j", ">", "i"}], ",", "\[IndentingNewLine]", RowBox[{"sum", "+=", RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xOld", "[", RowBox[{"[", "j", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"xNew", "[", RowBox[{"[", "i", "]"}], "]"}], "=", RowBox[{ FractionBox[ RowBox[{ RowBox[{"-", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xOld", "[", RowBox[{"[", "j", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"i", "-", "1"}]}], "}"}]}], "]"}]}], "-", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xOld", "[", RowBox[{"[", "j", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"i", "+", "1"}], ",", "n"}], "}"}]}], "]"}]}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]], "+", FractionBox[ RowBox[{"b", "[", RowBox[{"[", "i", "]"}], "]"}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]]}]}]}]}], "\[IndentingNewLine]", "]"}], ";"}], "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"Norm", "[", RowBox[{"xNew", "-", "xOld"}], "]"}], "/", RowBox[{"Norm", "[", "xNew", "]"}]}], "\[GreaterEqual]", "\[Epsilon]"}], "&&", RowBox[{"iter", "<", "maxIter"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"xOld", "=", "xNew"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", "n"}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"sum", " ", "=", " ", "0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "\[LessEqual]", "n"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"j", "<", "i"}], ",", "\[IndentingNewLine]", RowBox[{"sum", "+=", RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xNew", "[", RowBox[{"[", "j", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"j", ">", "i"}], ",", "\[IndentingNewLine]", RowBox[{"sum", "+=", RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xOld", "[", RowBox[{"[", "j", "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"xNew", "[", RowBox[{"[", "i", "]"}], "]"}], "=", RowBox[{ FractionBox[ RowBox[{ RowBox[{"-", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xNew", "[", RowBox[{"[", "j", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"i", "-", "1"}]}], "}"}]}], "]"}]}], "-", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"xOld", "[", RowBox[{"[", "j", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"i", "+", "1"}], ",", "n"}], "}"}]}], "]"}]}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]], "+", FractionBox[ RowBox[{"b", "[", RowBox[{"[", "i", "]"}], "]"}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]]}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"iter", "++"}]}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "xNew", "\[IndentingNewLine]", "iter"}], \ "Input", CellChangeTimes->{{3.6597795644573717`*^9, 3.659779564727372*^9}, { 3.659779672121047*^9, 3.6597797636082797`*^9}, {3.659779803876583*^9, 3.6597800806874156`*^9}, 3.6598527901310143`*^9, {3.754024660331521*^9, 3.754024718527849*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ "3.0050048828125`", ",", "1.016143798828125`", ",", "1.0068206787109375`"}], "}"}]], "Output", CellChangeTimes->{{3.659780011672468*^9, 3.6597800511437263`*^9}, 3.6597800812584486`*^9, {3.659852890498556*^9, 3.6598528932116365`*^9}, { 3.7540247099553595`*^9, 3.754024719203888*^9}}], Cell[BoxData["4"], "Output", CellChangeTimes->{{3.659780011672468*^9, 3.6597800511437263`*^9}, 3.6597800812584486`*^9, {3.659852890498556*^9, 3.6598528932116365`*^9}, { 3.7540247099553595`*^9, 3.7540247192098885`*^9}}] }, Open ]], Cell[BoxData["."], "Input", CellChangeTimes->{3.659852890498556*^9}] }, WindowSize->{1026, 789}, WindowMargins->{{Automatic, 163}, {Automatic, 0}}, FrontEndVersion->"10.1 for Microsoft Windows (64-bit) (March 23, 2015)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 7643, 214, 856, "Input"], Cell[8226, 238, 335, 7, 31, "Output"], Cell[8564, 247, 226, 3, 31, "Output"] }, Open ]], Cell[8805, 253, 69, 1, 31, "Input"] } ] *) (* End of internal cache information *)