(* 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[ 7099, 212] NotebookOptionsPosition[ 6743, 195] NotebookOutlinePosition[ 7089, 210] CellTagsIndexPosition[ 7046, 207] 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.0001"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"maxIter", "=", "100"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"iter", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"xOld", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "n"}], "}"}]}], "]"}]}], ";"}], " "}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"xNew", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "n"}], "}"}]}], "]"}]}], ";"}], " "}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", "n"}], ",", RowBox[{"i", "++"}], ",", " ", RowBox[{"(*", RowBox[{"Compute", " ", "the", " ", "first", " ", "approximation", " ", SubscriptBox["x", "1"]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"sum", " ", "=", " ", "0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "\[LessEqual]", "n"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"j", "\[NotEqual]", "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[{"-", "sum"}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]], "+", FractionBox[ RowBox[{"b", "[", RowBox[{"[", "i", "]"}], "]"}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]]}]}]}]}], "\[IndentingNewLine]", "]"}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Compute", " ", "the", " ", "successive", " ", "approximations", " ", "until", " ", "the", " ", "desired", " ", "accuracy", " ", "is", " ", "reached", " ", "or", "\[IndentingNewLine]", "the", " ", "maximum", " ", "number", " ", "of", " ", "iterations", " ", "is", " ", "reached"}], "*)"}]}], "\[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[{"If", "[", RowBox[{ RowBox[{"j", "\[NotEqual]", "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[{"-", "sum"}], 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.6597800507907057`*^9}, {3.6598531753407445`*^9, 3.6598533105899734`*^9}, { 3.66067880389182*^9, 3.6606788100151534`*^9}, {3.754024485730534*^9, 3.7540246231423936`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{ "3.000046003551688`", ",", "0.9999371281774074`", ",", "1.0000628122179478`"}], "}"}]], "Output", CellChangeTimes->{{3.659780011672468*^9, 3.6597800511437263`*^9}, { 3.754024612851805*^9, 3.7540246235044146`*^9}}], Cell[BoxData["25"], "Output", CellChangeTimes->{{3.659780011672468*^9, 3.6597800511437263`*^9}, { 3.754024612851805*^9, 3.7540246235054145`*^9}}] }, Open ]] }, WindowSize->{1026, 729}, WindowMargins->{{Automatic, 139}, {114, Automatic}}, 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, 5731, 158, 776, "Input"], Cell[6314, 182, 262, 6, 31, "Output"], Cell[6579, 190, 148, 2, 31, "Output"] }, Open ]] } ] *) (* End of internal cache information *)