(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 9.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 157, 7] NotebookDataLength[ 11329, 332] NotebookOptionsPosition[ 11085, 319] NotebookOutlinePosition[ 11427, 334] CellTagsIndexPosition[ 11384, 331] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{"sistema", " ", RowBox[{"ejemplo", ":", " ", "\[IndentingNewLine]", RowBox[{"A", ".", "x"}]}]}], "=", "b"}], ",", RowBox[{ RowBox[{"siendo", " ", "A"}], "=", TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"4", RowBox[{"-", "1"}], "1"}, {"4", RowBox[{"-", "8"}], "1"}, { RowBox[{"-", "2"}], RowBox[{"-", "1"}], "5"} }], "\[NoBreak]", ")"}], MatrixForm[#]& ]}], ",", RowBox[{ RowBox[{"y", " ", "b"}], "=", RowBox[{ RowBox[{ RowBox[{"(", "\[NoBreak]", GridBox[{ {"7"}, { RowBox[{"-", "21"}]}, {"15"} }], "\[NoBreak]", ")"}], " ", "x0"}], "=", InterpretationBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1"}, {"2"}, {"2"} }], "\[NoBreak]", ")"}], MatrixForm[{1, 2, 2}]]}]}]}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"para", " ", "calcular", " ", "la", " ", "Tg"}], " ", "=", " ", RowBox[{"-", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{"D", "+", "L"}], ")"}], RowBox[{"-", "1"}]], ".", "U"}]}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"diag", "=", RowBox[{"DiagonalMatrix", "[", RowBox[{"Diagonal", "[", "A", "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"L", "=", RowBox[{ RowBox[{"LowerTriangularize", "[", "A", "]"}], "-", "diag"}]}], ";", RowBox[{"MatrixForm", "[", "L", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"U", "=", RowBox[{ RowBox[{"UpperTriangularize", "[", "A", "]"}], "-", "diag"}]}], ";", RowBox[{"MatrixForm", "[", "U", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Tg", "=", RowBox[{"-", RowBox[{ RowBox[{"Inverse", "[", RowBox[{"diag", "+", "L"}], "]"}], ".", "U"}]}]}], ";", RowBox[{"MatrixForm", "[", "Tg", "]"}]}], "\[IndentingNewLine]", RowBox[{"Max", "[", RowBox[{"Abs", "[", RowBox[{"Eigenvalues", "[", "Tg", "]"}], "]"}], "]"}], "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"Bucle", " ", "para", " ", "Gauss"}], "-", RowBox[{"Seidel", RowBox[{"(", " ", RowBox[{ RowBox[{"k", " ", "y", " ", "k"}], "+", "1"}], ")"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"4.", ",", RowBox[{"-", "1."}], ",", "1."}], "}"}], ",", RowBox[{"{", RowBox[{"4.", ",", RowBox[{"-", "8."}], ",", "1."}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2."}], ",", RowBox[{"-", "1."}], ",", "5."}], "}"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "=", RowBox[{"{", RowBox[{"7.", ",", RowBox[{"-", "21."}], ",", "15."}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Length", "[", "b", "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"aproximacion", " ", "inicial"}], ",", " ", RowBox[{"y", " ", "usando", " ", "while", " ", "con", " ", "la", " ", RowBox[{"tolerancia", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xant", "=", RowBox[{"{", RowBox[{"0.", ",", "0", ",", "0"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xnuev", "=", "xant"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"error", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tol", "=", RowBox[{"10", "^", RowBox[{"(", RowBox[{"-", "4"}], ")"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "=", "0"}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"bucle", " ", "principal", " ", "while"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{"error", "\[GreaterEqual]", "tol"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"k", "=", RowBox[{"k", "+", "1"}]}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", "\t", RowBox[{ RowBox[{ RowBox[{"xnuev", "[", RowBox[{"[", "i", "]"}], "]"}], "=", RowBox[{ FractionBox["1", RowBox[{"a", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]], "*", RowBox[{"(", RowBox[{ RowBox[{"b", "[", RowBox[{"[", "i", "]"}], "]"}], "-", RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"j", "=", "1"}], RowBox[{"i", "-", "1"}]], RowBox[{ RowBox[{"a", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "*", RowBox[{"xnuev", "[", RowBox[{"[", "j", "]"}], "]"}]}]}], "-", RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"j", "=", RowBox[{"i", "+", "1"}]}], "n"], RowBox[{ RowBox[{"a", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "*", RowBox[{"xant", "[", RowBox[{"[", "j", "]"}], "]"}]}]}]}], ")"}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "k"}], "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "xnuev"}], "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"error", "=", RowBox[{ RowBox[{"Norm", "[", RowBox[{ RowBox[{"xnuev", "-", "xant"}], ",", "\[Infinity]"}], "]"}], "/", RowBox[{"Norm", "[", RowBox[{"xnuev", ",", "\[Infinity]"}], "]"}]}]}], " ", ";", "\[IndentingNewLine]", " ", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "error"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"xant", "=", "xnuev"}]}]}], "]"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "si", " ", "ponemos", " ", "el", " ", "numero", " ", "de", " ", "iteraciones", " ", "K"}], ",", " ", RowBox[{"con", " ", "dos", " ", "Do", " ", "anidados"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"A", "=", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"4.", ",", RowBox[{"-", "1."}], ",", "1."}], "}"}], ",", RowBox[{"{", RowBox[{"4.", ",", RowBox[{"-", "8."}], ",", "1."}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2."}], ",", RowBox[{"-", "1."}], ",", "5."}], "}"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "=", RowBox[{"{", RowBox[{"7", ",", RowBox[{"-", "21"}], ",", "15"}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Length", "[", "b", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xant", "=", RowBox[{"{", RowBox[{"1.", ",", "2.", ",", "2."}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xnuev", "=", "xant"}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"bucle", " ", "principal", " ", "Do", " ", "anidados"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", "\t", RowBox[{ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"xnuev", "[", RowBox[{"[", "i", "]"}], "]"}], "=", RowBox[{ FractionBox["1", RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]], "*", RowBox[{"(", RowBox[{ RowBox[{"b", "[", RowBox[{"[", "i", "]"}], "]"}], "-", RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"j", "=", "1"}], RowBox[{"i", "-", "1"}]], RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "*", RowBox[{"xnuev", "[", RowBox[{"[", "j", "]"}], "]"}]}]}], "-", RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"j", "=", RowBox[{"i", "+", "1"}]}], "n"], RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "*", RowBox[{"xant", "[", RowBox[{"[", "j", "]"}], "]"}]}]}]}], ")"}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "n"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", "\t ", RowBox[{"Print", "[", "xnuev", "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"erabs", "=", RowBox[{"Norm", "[", RowBox[{ RowBox[{"xnuev", "-", "xant"}], ",", "\[Infinity]"}], "]"}]}], ";", "\[IndentingNewLine]", " ", RowBox[{"errel", "=", RowBox[{"erabs", "/", RowBox[{"Norm", "[", RowBox[{"xnuev", ",", "\[Infinity]"}], "]"}]}]}], ";", " ", "\[IndentingNewLine]", " ", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "erabs"}], "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "errel"}], "]"}], ";", "\[IndentingNewLine]", "\t ", RowBox[{"xant", "=", "xnuev"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"k", ",", "1", ",", "5"}], "}"}]}], "]"}]}]}]], "Input", CellChangeTimes->{{3.6560984504312983`*^9, 3.656098505547509*^9}, { 3.6560987006781044`*^9, 3.6560987440550575`*^9}}] }, WindowSize->{716, 537}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, FrontEndVersion->"9.0 for Microsoft Windows (32-bit) (January 25, 2013)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[557, 20, 10524, 297, 1357, "Input"] } ] *) (* End of internal cache information *)