(* 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[ 6703, 181] NotebookOptionsPosition[ 6460, 168] NotebookOutlinePosition[ 6804, 183] CellTagsIndexPosition[ 6761, 180] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[ RowBox[{ RowBox[{"SeidelIteration", "[", RowBox[{"A_", ",", "b_"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Length", "[", "A", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"\[Epsilon]", "=", "0.0001"}], ";", "\[IndentingNewLine]", RowBox[{"maxIter", "=", "100"}], ";", "\[IndentingNewLine]", RowBox[{"iter", "=", "1"}], ";", "\[IndentingNewLine]", RowBox[{"xOld", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"xNew", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "n"}], "}"}]}], "]"}]}], ";", "\[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[{"-", "sum"}], 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[{"-", "sum"}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]], "+", FractionBox[ RowBox[{"b", "[", RowBox[{"[", "i", "]"}], "]"}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]]}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"iter", "++"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"xNew", ",", "iter"}], "}"}]}], "\[IndentingNewLine]", ")"}]}]], "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}, {3.7872857685138593`*^9, 3.787285796828479*^9}, { 3.787285828526292*^9, 3.787285896596185*^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[558, 20, 5898, 146, 866, "Input"] } ] *) (* End of internal cache information *)