(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 17326, 601] NotebookOptionsPosition[ 15961, 549] NotebookOutlinePosition[ 16367, 565] CellTagsIndexPosition[ 16324, 562] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ Math 481A California State University, Northridge Hermite Interpolating Polynomials\ \>", "Section"], Cell["\[Copyright]2005 BE Shapiro", "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Lagrange Interpolating Function: Calculates ", Cell[BoxData[ FormBox[ RowBox[{ SubscriptBox["L", RowBox[{"n", ",", "0"}]], ",", SubscriptBox["L", RowBox[{"n", ",", "1"}]], ",", "...", ",", SubscriptBox["L", RowBox[{"n", ",", "n"}]]}], TraditionalForm]]] }], "Section"], Cell[BoxData[ RowBox[{ RowBox[{"Lagrange", "[", RowBox[{ RowBox[{"{", "xj__", "}"}], ",", "x_"}], "]"}], ":=", " ", RowBox[{"Module", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{ "i", ",", "n", ",", "xi", ",", " ", "xjc", ",", "L", ",", "xgrid", ",", "num", ",", "den"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"xgrid", " ", "=", " ", RowBox[{"{", "xj", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"n", "=", RowBox[{"Length", "[", "xgrid", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"L", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", " ", "n"}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"xi", "=", RowBox[{"xgrid", "[", RowBox[{"[", "i", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"xjc", "=", " ", RowBox[{"Complement", "[", RowBox[{"xgrid", ",", RowBox[{"{", "xi", "}"}]}], "]"}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"den", " ", "=", " ", RowBox[{"Times", "@@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"xi", "-", "#"}], ")"}], "&"}], "/@", "xjc"}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"num", " ", "=", " ", RowBox[{"Times", "@@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"x", "-", "#"}], ")"}], "&"}], "/@", "xjc"}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"L", "=", RowBox[{"Append", "[", RowBox[{"L", ",", " ", RowBox[{"Expand", "[", RowBox[{"num", "/", "den"}], "]"}]}], "]"}]}], ";"}]}], " ", "\[IndentingNewLine]", "]"}], ";", " ", "\[IndentingNewLine]", RowBox[{"Return", "[", "L", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Hermite Interpolation\nGiven: ", Cell[BoxData[ FormBox[ RowBox[{ SubscriptBox["x", "0"], ",", "..", ",", RowBox[{ SubscriptBox["x", "n"], ";", " ", SubscriptBox["f", "0"]}], ",", "\[Ellipsis]", ",", RowBox[{ SubscriptBox["f", "n"], ";", SuperscriptBox[ SubscriptBox["f", "0"], "\[Prime]"]}], ",", SuperscriptBox[ SubscriptBox[ StyleBox[ RowBox[{"\[Ellipsis]", StyleBox["f", FontSlant->"Italic"]}]], "n"], "\[Prime]"]}], TraditionalForm]]], ";", StyleBox["t", FontSlant->"Italic"], "\nDetermine: ", Cell[BoxData[ FormBox[ RowBox[{ SubscriptBox["H", RowBox[{ RowBox[{"2", "n"}], "+", "1"}]], "(", "t", ")"}], TraditionalForm]]] }], "Section"], Cell[BoxData[ RowBox[{ RowBox[{"Hermite", "[", RowBox[{ RowBox[{"{", "x__", "}"}], ",", " ", RowBox[{"{", "f__", "}"}], ",", " ", RowBox[{"{", "fprime__", "}"}], ",", "t_"}], "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "L", ",", "L2", ",", "Lprime", ",", "z", ",", "H", ",", "HH", ",", "H2NP1"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"L", "=", RowBox[{"Lagrange", "[", RowBox[{ RowBox[{"{", "x", "}"}], ",", " ", "z"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Lprime", "=", RowBox[{"MapThread", "[", RowBox[{ RowBox[{ RowBox[{"#1", "/.", RowBox[{"{", RowBox[{"z", "\[Rule]", " ", "#2"}], "}"}]}], "&"}], ",", RowBox[{"{", RowBox[{ RowBox[{"D", "[", RowBox[{"L", ",", "z"}], "]"}], ",", RowBox[{"{", "x", "}"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"L2", "=", RowBox[{"L", "^", "2"}]}], ";", "\[IndentingNewLine]", RowBox[{"HH", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"t", "-", "#"}], ")"}], "&"}], "/@", RowBox[{"{", "x", "}"}]}], ")"}], "*", "L2"}], ")"}], "/.", RowBox[{"{", RowBox[{"z", "\[Rule]", " ", "t"}], "}"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"H", "=", RowBox[{ RowBox[{"(", RowBox[{"L2", "-", RowBox[{"2", "*", "Lprime", "*", "HH"}]}], ")"}], "/.", RowBox[{"{", RowBox[{"z", "\[Rule]", " ", "t"}], "}"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"H2NP1", "=", RowBox[{ RowBox[{"H", ".", RowBox[{"{", "f", "}"}]}], "+", RowBox[{"HH", ".", RowBox[{"{", "fprime", "}"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"H2NP1", "//", "Expand"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Example ", "Section"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Hermite", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"13", "/", "10"}], ",", RowBox[{"16", "/", "10"}], ",", " ", RowBox[{"19", "/", "10"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{".6200860", ",", ".4554022", ",", ".2818186"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", ".5220232"}], ",", RowBox[{"-", ".5698959"}], ",", RowBox[{"-", ".5811571"}]}], "}"}], ",", "t"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"1.0019440646915427`", "\[InvisibleSpace]", "-", RowBox[{"0.008229223456510226`", " ", "t"}], "-", RowBox[{"0.23521616975449433`", " ", SuperscriptBox["t", "2"]}], "-", RowBox[{"0.014556080246620695`", " ", SuperscriptBox["t", "3"]}], "+", RowBox[{"0.02403179012333112`", " ", SuperscriptBox["t", "4"]}], "-", RowBox[{"0.002774691358013115`", " ", SuperscriptBox["t", "5"]}]}]], "Output", CellChangeTimes->{3.396048018719132*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Hermite", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"13", "/", "10"}], ",", RowBox[{"16", "/", "10"}], ",", " ", RowBox[{"19", "/", "10"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{".6200860", ",", ".4554022", ",", ".2818186"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", ".5220232"}], ",", RowBox[{"-", ".5698959"}], ",", RowBox[{"-", ".5811571"}]}], "}"}], ",", "1.5"}], "]"}]], "Input"], Cell[BoxData["0.5118277017284`"], "Output", CellChangeTimes->{3.3960480216698627`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Hermite", "[", RowBox[{ RowBox[{"Range", "[", RowBox[{"5", ",", "25", ",", " ", "5."}], "]"}], ",", " ", RowBox[{"Sqrt", "/@", RowBox[{"Range", "[", RowBox[{"5", ",", " ", "25", ",", "5"}], "]"}]}], ",", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "/", "2"}], ")"}], " ", RowBox[{"#", "^", RowBox[{"(", RowBox[{ RowBox[{"-", "1"}], "/", "2"}], ")"}]}]}], "&"}], "/@", RowBox[{"Range", "[", RowBox[{"5", ",", "25", ",", " ", "5"}], "]"}]}], ",", " ", "x"}], "]"}]], "Input", CellChangeTimes->{{3.396048022894575*^9, 3.396048141905532*^9}}], Cell[BoxData[ RowBox[{"0.6219575959109989`", "\[InvisibleSpace]", "+", RowBox[{"0.49216992867650333`", " ", "x"}], "-", RowBox[{"0.055207592028551744`", " ", SuperscriptBox["x", "2"]}], "+", RowBox[{"0.006239780585659105`", " ", SuperscriptBox["x", "3"]}], "-", RowBox[{"0.0005195999856537625`", " ", SuperscriptBox["x", "4"]}], "+", RowBox[{"0.00003033129074492269`", " ", SuperscriptBox["x", "5"]}], "-", RowBox[{"1.2024386407127885`*^-6", " ", SuperscriptBox["x", "6"]}], "+", RowBox[{"3.0767170350830784`*^-8", " ", SuperscriptBox["x", "7"]}], "-", RowBox[{"4.5766140083026215`*^-10", " ", SuperscriptBox["x", "8"]}], "+", RowBox[{"3.0032540033973023`*^-12", " ", SuperscriptBox["x", "9"]}]}]], "Output", CellChangeTimes->{ 3.396048043533091*^9, {3.396048112958416*^9, 3.396048142320128*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"Hermite", "[", RowBox[{ RowBox[{"Range", "[", RowBox[{"5", ",", "25", ",", " ", "5"}], "]"}], ",", " ", RowBox[{"Sqrt", "/@", RowBox[{"Range", "[", RowBox[{"5", ",", " ", "25", ",", "5"}], "]"}]}], ",", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "/", "2"}], ")"}], " ", RowBox[{"#", "^", RowBox[{"(", RowBox[{ RowBox[{"-", "1"}], "/", "2"}], ")"}]}]}], "&"}], "/@", RowBox[{"Range", "[", RowBox[{"5", ",", "25", ",", " ", "5"}], "]"}]}], ",", " ", "16."}], "]"}], "-", "4"}]], "Input", CellChangeTimes->{{3.3960481644926977`*^9, 3.396048217235775*^9}}], Cell[BoxData["9.342076419116552`*^-7"], "Output", CellChangeTimes->{{3.39604819293233*^9, 3.3960482178872643`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"f", "[", "x_", "]"}], ":=", " ", RowBox[{"Sqrt", "[", "x", "]"}]}], ";"}], " "}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xdata", "=", RowBox[{"Range", "[", RowBox[{"5", ",", "25", ",", "5"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"fdata", "=", RowBox[{"f", "/@", "xdata"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"fpdata", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{"f", "'"}], "[", "#", "]"}], "&"}], "/@", "xdata"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Hermite", "[", RowBox[{"xdata", ",", " ", "fdata", ",", " ", "fpdata", ",", " ", "x"}], "]"}]}], "Input", CellChangeTimes->{{3.39604855936547*^9, 3.3960486198948193`*^9}, { 3.3960487179678307`*^9, 3.3960487572056503`*^9}}], Cell[BoxData[ RowBox[{ FractionBox["320", "3"], "+", FractionBox[ RowBox[{"800", " ", SqrtBox["5"]}], "3"], "-", FractionBox[ RowBox[{"850", " ", SqrtBox["10"]}], "3"], "+", RowBox[{"50", " ", SqrtBox["15"]}], "-", FractionBox[ RowBox[{"4183", " ", "x"}], "45"], "-", RowBox[{"107", " ", SqrtBox[ FractionBox["5", "3"]], " ", "x"}], "-", FractionBox[ RowBox[{"8513", " ", SqrtBox["5"], " ", "x"}], "36"], "+", FractionBox[ RowBox[{"2164", " ", SqrtBox["10"], " ", "x"}], "9"], "+", FractionBox[ RowBox[{"1855", " ", SuperscriptBox["x", "2"]}], "54"], "+", RowBox[{ FractionBox["1981", "40"], " ", SqrtBox[ FractionBox["3", "5"]], " ", SuperscriptBox["x", "2"]}], "+", FractionBox[ RowBox[{"957113", " ", SuperscriptBox["x", "2"]}], RowBox[{"2160", " ", SqrtBox["5"]}]], "-", FractionBox[ RowBox[{"462653", " ", SuperscriptBox["x", "2"]}], RowBox[{"540", " ", SqrtBox["10"]}]], "-", FractionBox[ RowBox[{"76429", " ", SuperscriptBox["x", "3"]}], "10800"], "-", FractionBox[ RowBox[{"495269", " ", SuperscriptBox["x", "3"]}], RowBox[{"5400", " ", SqrtBox["5"]}]], "+", FractionBox[ RowBox[{"908491", " ", SuperscriptBox["x", "3"]}], RowBox[{"5400", " ", SqrtBox["10"]}]], "-", FractionBox[ RowBox[{"494", " ", SuperscriptBox["x", "3"]}], RowBox[{"25", " ", SqrtBox["15"]}]], "+", FractionBox[ RowBox[{"16169", " ", SuperscriptBox["x", "4"]}], "18000"], "+", RowBox[{ FractionBox["297", "800"], " ", SqrtBox[ FractionBox["3", "5"]], " ", SuperscriptBox["x", "4"]}], "+", FractionBox[ RowBox[{"166691", " ", SuperscriptBox["x", "4"]}], RowBox[{"14400", " ", SqrtBox["5"]}]], "-", FractionBox[ RowBox[{"1811", " ", SuperscriptBox["x", "4"]}], RowBox[{"90", " ", SqrtBox["10"]}]], "-", FractionBox[ RowBox[{"131551", " ", SuperscriptBox["x", "5"]}], "1800000"], "+", FractionBox[ RowBox[{"119", " ", SqrtBox[ FractionBox["3", "5"]], " ", SuperscriptBox["x", "5"]}], "20000"], "-", FractionBox[ RowBox[{"166873", " ", SuperscriptBox["x", "5"]}], RowBox[{"180000", " ", SqrtBox["5"]}]], "+", FractionBox[ RowBox[{"68747", " ", SuperscriptBox["x", "5"]}], RowBox[{"45000", " ", SqrtBox["10"]}]], "+", FractionBox[ RowBox[{"43", " ", SuperscriptBox["x", "6"]}], "11250"], "-", FractionBox[ RowBox[{"101", " ", SqrtBox[ FractionBox["3", "5"]], " ", SuperscriptBox["x", "6"]}], "50000"], "+", FractionBox[ RowBox[{"42559", " ", SuperscriptBox["x", "6"]}], RowBox[{"900000", " ", SqrtBox["5"]}]], "-", FractionBox[ RowBox[{"8327", " ", SuperscriptBox["x", "6"]}], RowBox[{"112500", " ", SqrtBox["10"]}]], "-", FractionBox[ RowBox[{"559", " ", SuperscriptBox["x", "7"]}], "4500000"], "-", FractionBox[ RowBox[{"223", " ", SuperscriptBox["x", "7"]}], RowBox[{"150000", " ", SqrtBox["5"]}]], "+", FractionBox[ RowBox[{"499", " ", SuperscriptBox["x", "7"]}], RowBox[{"225000", " ", SqrtBox["10"]}]], "+", FractionBox[ RowBox[{"17", " ", SuperscriptBox["x", "7"]}], RowBox[{"50000", " ", SqrtBox["15"]}]], "+", FractionBox[ RowBox[{"77", " ", SuperscriptBox["x", "8"]}], "33750000"], "-", FractionBox[ RowBox[{"7", " ", SqrtBox[ FractionBox["3", "5"]], " ", SuperscriptBox["x", "8"]}], "2500000"], "+", FractionBox[ RowBox[{"3541", " ", SuperscriptBox["x", "8"]}], RowBox[{"135000000", " ", SqrtBox["5"]}]], "-", FractionBox[ RowBox[{"79", " ", SuperscriptBox["x", "8"]}], RowBox[{"2109375", " ", SqrtBox["10"]}]], "-", FractionBox[ RowBox[{"61", " ", SuperscriptBox["x", "9"]}], "3375000000"], "-", FractionBox[ RowBox[{"67", " ", SuperscriptBox["x", "9"]}], RowBox[{"337500000", " ", SqrtBox["5"]}]], "+", FractionBox[ RowBox[{"23", " ", SuperscriptBox["x", "9"]}], RowBox[{"84375000", " ", SqrtBox["10"]}]], "+", FractionBox[ SuperscriptBox["x", "9"], RowBox[{"12500000", " ", SqrtBox["15"]}]]}]], "Output", CellChangeTimes->{3.396048620452168*^9, 3.396048757563919*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"Hermite", "[", RowBox[{"xdata", ",", " ", "fdata", ",", " ", "fpdata", ",", " ", "16"}], "]"}], "-", "4.0"}]], "Input", CellChangeTimes->{{3.396048820749016*^9, 3.39604884455058*^9}}], Cell[BoxData["9.342077436080842`*^-7"], "Output", CellChangeTimes->{{3.39604882287888*^9, 3.396048844839169*^9}}] }, Open ]] }, Open ]] }, WindowSize->{657, 967}, WindowMargins->{{146, Automatic}, {3, Automatic}}, FrontEndVersion->"6.0 for Mac OS X x86 (32-bit) (June 19, 2007)", StyleDefinitions->FrontEnd`FileName[{"Creative"}, "PastelColor.nb", CharacterEncoding -> "UTF-8"] ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 110, 4, 112, "Section"], Cell[703, 29, 49, 0, 34, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[789, 34, 324, 11, 76, "Section"], Cell[1116, 47, 2130, 55, 233, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3283, 107, 774, 29, 118, "Section"], Cell[4060, 138, 2118, 63, 173, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[6215, 206, 27, 0, 72, "Section"], Cell[CellGroupData[{ Cell[6267, 210, 479, 14, 53, "Input"], Cell[6749, 226, 484, 11, 59, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7270, 242, 481, 14, 53, "Input"], Cell[7754, 258, 87, 1, 37, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7878, 264, 673, 20, 53, "Input"], Cell[8554, 286, 859, 20, 77, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9450, 311, 717, 21, 53, "Input"], Cell[10170, 334, 116, 1, 40, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[10323, 340, 837, 25, 98, "Input"], Cell[11163, 367, 4389, 165, 452, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[15589, 537, 227, 5, 37, "Input"], Cell[15819, 544, 114, 1, 40, "Output"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)