Newer
Older
Lecture_repo / Lectures_my / NumMet / Lecture3 / examples / surprise.nb
@Danny van Dyk Danny van Dyk on 19 Sep 2016 13 KB add preliminary lecture 3
(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 10.3' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       158,          7]
NotebookDataLength[     13628,        453]
NotebookOptionsPosition[     12908,        423]
NotebookOutlinePosition[     13243,        438]
CellTagsIndexPosition[     13200,        435]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 RowBox[{
  RowBox[{"f", "[", "x_", "]"}], " ", ":=", " ", 
  RowBox[{"1", " ", "/", " ", 
   RowBox[{"(", 
    RowBox[{"1", " ", "+", " ", 
     RowBox[{"25", " ", "*", " ", 
      RowBox[{"x", "^", "2"}]}]}], ")"}]}]}]], "Input",
 CellChangeTimes->{{3.683213270757375*^9, 3.683213279924851*^9}, {
  3.683213869842869*^9, 3.683213902127639*^9}}],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"data", " ", "=", "\[IndentingNewLine]", 
  RowBox[{"Table", "[", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"Table", "[", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
        RowBox[{"1", "/", 
         RowBox[{"2", "^", "i"}]}], ",", " ", 
        RowBox[{"f", "[", 
         RowBox[{"1", "/", 
          RowBox[{"2", "^", " ", "i"}]}], "]"}]}], "}"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"{", 
       RowBox[{"i", ",", " ", "1", ",", " ", "n"}], "}"}]}], 
     "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", 
    RowBox[{"{", 
     RowBox[{"n", ",", " ", "1", ",", " ", "10"}], "}"}]}], 
   "\[IndentingNewLine]", "]"}]}]], "Input",
 CellChangeTimes->{{3.683213281504025*^9, 3.68321336409263*^9}, {
  3.6832134308264723`*^9, 3.6832135030974703`*^9}, {3.68321392840974*^9, 
  3.683213928656291*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
   RowBox[{"{", 
    RowBox[{"{", 
     RowBox[{
      FractionBox["1", "2"], ",", 
      FractionBox["4", "29"]}], "}"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "16"], ",", 
       FractionBox["256", "281"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "16"], ",", 
       FractionBox["256", "281"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "32"], ",", 
       FractionBox["1024", "1049"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "16"], ",", 
       FractionBox["256", "281"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "32"], ",", 
       FractionBox["1024", "1049"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "64"], ",", 
       FractionBox["4096", "4121"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "16"], ",", 
       FractionBox["256", "281"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "32"], ",", 
       FractionBox["1024", "1049"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "64"], ",", 
       FractionBox["4096", "4121"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "128"], ",", 
       FractionBox["16384", "16409"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "16"], ",", 
       FractionBox["256", "281"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "32"], ",", 
       FractionBox["1024", "1049"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "64"], ",", 
       FractionBox["4096", "4121"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "128"], ",", 
       FractionBox["16384", "16409"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "256"], ",", 
       FractionBox["65536", "65561"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "16"], ",", 
       FractionBox["256", "281"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "32"], ",", 
       FractionBox["1024", "1049"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "64"], ",", 
       FractionBox["4096", "4121"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "128"], ",", 
       FractionBox["16384", "16409"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "256"], ",", 
       FractionBox["65536", "65561"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "512"], ",", 
       FractionBox["262144", "262169"]}], "}"}]}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "2"], ",", 
       FractionBox["4", "29"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "4"], ",", 
       FractionBox["16", "41"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "8"], ",", 
       FractionBox["64", "89"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "16"], ",", 
       FractionBox["256", "281"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "32"], ",", 
       FractionBox["1024", "1049"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "64"], ",", 
       FractionBox["4096", "4121"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "128"], ",", 
       FractionBox["16384", "16409"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "256"], ",", 
       FractionBox["65536", "65561"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "512"], ",", 
       FractionBox["262144", "262169"]}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{
       FractionBox["1", "1024"], ",", 
       FractionBox["1048576", "1048601"]}], "}"}]}], "}"}]}], "}"}]], "Output",\

 CellChangeTimes->{{3.683213359972814*^9, 3.683213364316153*^9}, {
   3.683213477324293*^9, 3.68321350403498*^9}, 3.683213872785676*^9, {
   3.683213903889242*^9, 3.683213928925227*^9}}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"data", "[", 
  RowBox[{"[", "1", "]"}], "]"}]], "Input",
 CellChangeTimes->{{3.683213488468143*^9, 3.6832135074848843`*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"{", 
   RowBox[{
    FractionBox["1", "2"], ",", 
    FractionBox["4", "29"]}], "}"}], "}"}]], "Output",
 CellChangeTimes->{
  3.6832135076672087`*^9, 3.683213874950424*^9, {3.683213905188409*^9, 
   3.6832139300981283`*^9}}]
}, Open  ]],

Cell[BoxData[
 RowBox[{
  RowBox[{"int", "[", 
   RowBox[{"i_", ",", " ", "h_"}], "]"}], " ", ":=", " ", 
  RowBox[{
   RowBox[{"InterpolatingPolynomial", "[", 
    RowBox[{
     RowBox[{"data", "[", 
      RowBox[{"[", "i", "]"}], "]"}], ",", " ", "h"}], "]"}], " ", "//", " ", 
   "N"}]}]], "Input",
 CellChangeTimes->{{3.683213376089913*^9, 3.683213414838382*^9}, {
  3.683213480413106*^9, 3.683213487134054*^9}, {3.683213522852931*^9, 
  3.683213523379961*^9}}],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"points", " ", "=", " ", 
  RowBox[{"Table", "[", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"i", ",", " ", 
      RowBox[{"int", "[", 
       RowBox[{"i", ",", " ", "0"}], "]"}]}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{"{", 
     RowBox[{"i", ",", " ", "1", ",", " ", "10"}], "}"}]}], 
   "\[IndentingNewLine]", "]"}]}]], "Input",
 CellChangeTimes->{{3.683213517555332*^9, 3.683213551888112*^9}, {
  3.683213614699768*^9, 3.683213615827732*^9}, {3.683213936872109*^9, 
  3.683213937958345*^9}}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
   RowBox[{"{", 
    RowBox[{"1", ",", "0.13793103448275862`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"2", ",", "0.6425567703952901`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"3", ",", "1.1830922028708857`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"4", ",", "1.1124700238275869`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"5", ",", "0.9993142437021209`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"6", ",", "0.9986229233405193`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"7", ",", "0.9999957954211367`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"8", ",", "1.0000010454155606`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"9", ",", "1.0000000011009504`"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"10", ",", "0.9999999999502306`"}], "}"}]}], "}"}]], "Output",
 CellChangeTimes->{
  3.683213552145316*^9, 3.683213616439742*^9, {3.683213877283555*^9, 
   3.6832139382133007`*^9}}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"ListPlot", "[", "points", "]"}]], "Input",
 CellChangeTimes->{{3.683213601480364*^9, 3.6832136201453857`*^9}}],

Cell[BoxData[
 GraphicsBox[{{}, {{}, 
    {RGBColor[0.368417, 0.506779, 0.709798], PointSize[0.012833333333333334`],
      AbsoluteThickness[1.6], 
     PointBox[{{1., 0.13793103448275862`}, {2., 0.6425567703952901}, {3., 
      1.1830922028708857`}, {4., 1.1124700238275869`}, {5., 
      0.9993142437021209}, {6., 0.9986229233405193}, {7., 
      0.9999957954211367}, {8., 1.0000010454155606`}, {9., 
      1.0000000011009504`}, {10., 0.9999999999502306}}]}, {}}, {}},
  AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948],
  Axes->{True, True},
  AxesLabel->{None, None},
  AxesOrigin->{0, 0},
  DisplayFunction->Identity,
  Frame->{{False, False}, {False, False}},
  FrameLabel->{{None, None}, {None, None}},
  FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}},
  GridLines->{None, None},
  GridLinesStyle->Directive[
    GrayLevel[0.5, 0.4]],
  Method->{},
  PlotRange->{{0, 10.}, {0, 1.1830922028708857`}},
  PlotRangeClipping->True,
  PlotRangePadding->{{
     Scaled[0.02], 
     Scaled[0.02]}, {
     Scaled[0.02], 
     Scaled[0.05]}},
  Ticks->{Automatic, Automatic}]], "Output",
 CellChangeTimes->{
  3.683213620524157*^9, 3.683213880453622*^9, {3.683213912494602*^9, 
   3.683213939084776*^9}}]
}, Open  ]]
},
WindowSize->{958, 1059},
WindowMargins->{{0, Automatic}, {2, Automatic}},
FrontEndVersion->"10.3 for Linux x86 (64-bit) (October 9, 2015)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 360, 9, 32, "Input"],
Cell[CellGroupData[{
Cell[943, 33, 883, 22, 187, "Input"],
Cell[1829, 57, 7203, 245, 409, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[9069, 307, 148, 3, 32, "Input"],
Cell[9220, 312, 265, 8, 49, "Output"]
}, Open  ]],
Cell[9500, 323, 465, 12, 32, "Input"],
Cell[CellGroupData[{
Cell[9990, 339, 557, 14, 99, "Input"],
Cell[10550, 355, 944, 25, 55, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[11531, 385, 134, 2, 32, "Input"],
Cell[11668, 389, 1224, 31, 240, "Output"]
}, Open  ]]
}
]
*)

(* End of internal cache information *)