(* 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[ 11474, 331] NotebookOptionsPosition[ 11228, 318] NotebookOutlinePosition[ 11572, 333] CellTagsIndexPosition[ 11529, 330] 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]", RowBox[{"(*", " ", RowBox[{"para", " ", "calcular", " ", "la", " ", "Tj"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Tj", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[Equal]", "j"}], ",", "0", ",", RowBox[{"-", FractionBox[ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}]]}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "n"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"MatrixForm", "[", "Tj", "]"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"y", " ", "el", " ", "radio", " ", "espectral"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Max", "[", RowBox[{"Abs", "[", RowBox[{"Eigenvalues", "[", "Tj", "]"}], "]"}], "]"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Bucle", " ", "para", " ", "Jacobi", " ", RowBox[{"(", RowBox[{"solo", " ", "k"}], ")"}]}], " ", "*)"}], "\[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[{"xant", "[", 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[{"xant", "[", 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"}], "}"}]}], "]"}], "\[IndentingNewLine]", "\[IndentingNewLine]"}]}]], "Input", CellChangeTimes->{{3.6560970899618254`*^9, 3.6560971520223722`*^9}, { 3.6560972745436616`*^9, 3.65609729806734*^9}, {3.6560976572892094`*^9, 3.656097676006983*^9}, {3.656097728227686*^9, 3.6560978081554203`*^9}, { 3.6560979002091312`*^9, 3.656098063951103*^9}, {3.6560981043007126`*^9, 3.656098106489189*^9}, {3.656098282808254*^9, 3.6560983341295404`*^9}, { 3.6560983891969233`*^9, 3.6560983953102045`*^9}, {3.6560987984505653`*^9, 3.6560988046400185`*^9}}] }, WindowSize->{716, 537}, WindowMargins->{{18, Automatic}, {Automatic, 23}}, 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, 10667, 296, 1336, "Input"] } ] *) (* End of internal cache information *)