(***********************************************************************

                    Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. The data for the notebook 
starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do one of 
the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the 
word CacheID, otherwise Mathematica-compatible applications may try to 
use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info@wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      5828,        179]*)
(*NotebookOutlinePosition[      8670,        271]*)
(*  CellTagsIndexPosition[      8422,        257]*)
(*WindowFrame->Normal*)



Notebook[{
Cell[TextData[{
  "NumericalMath",
  StyleBox["`", "MB"],
  "PolynomialFit",
  StyleBox["`", "MB"]
}], "Subsection",
  CellTags->{"S5.91.1", "1.1"}],

Cell[TextData[{
  "The ",
  StyleBox["Mathematica", "TI"],
  " function ",
  StyleBox["Fit", "MR"],
  " does linear least squares fitting to data. It allows any combination of \
basis functions. However, it is often the case that you want to do polynomial \
fitting and it would be easier if you did not have to explicitly list the \
basis functions. In addition, for high\[Hyphen]degree fitting, things often \
get rather unstable numerically if you give simple powers of a variable as \
basis functions. ",
  StyleBox["PolynomialFit", "MR"],
  " avoids these problems. "
}], "Text",
  CellTags->{"S5.91.1", "1.2"}],

Cell[BoxData[
    FormBox[
      StyleBox[
        FrameBox[
          StyleBox[GridBox[{
                {"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"PolynomialFit[\\\\\\\"\\\"\
, \\\"MR\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\"data\\\\\\\"\\\", \
\\\"TI\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\",\\\\\\\"\\\", \\\"MR\\\"]\\) \\!\
\\(\\*StyleBox[\\\"\\\\\\\"n\\\\\\\"\\\", \
\\\"TI\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\"]\\\\\\\"\\\", \\\"MR\\\"]\\) \
\"\>", 
                  
                  RowBox[{"\<\"give the least squares \
\\!\\(\\*StyleBox[\\\"\\\\\\\"n\\\\\\\"\\\", \\\"TI\\\"]\\)\"\>", 
                    StyleBox[\(\[Null]\^th\),
                      
                      "InlineFormula"], "\<\" degree polynomial fit to \\!\\(\
\\*StyleBox[\\\"\\\\\\\"data\\\\\\\"\\\", \\\"TI\\\"]\\)\"\>"}]}
                },
              ColumnAlignments->{Right, Left}],
            GridBoxOptions->{RowLines->False}]],
        "2ColumnBox"], TraditionalForm]], "Text",
  CellTags->{"S5.91.1", "1.3"}],

Cell["Fitting polynomials to data. ", "Caption",
  CellTags->"S5.91.1"],

Cell[TextData[{
  StyleBox["PolynomialFit", "MR"],
  " uses the function ",
  StyleBox["Fit", "MR"],
  ", but it chooses a more appropriate set of basis functions than simple \
powers of a variable. It also returns a pure function rather than an \
expression and evaluates the function in a numerically stable way. If you \
want, you can evaluate the function at a symbolic point and expand the result \
to get an ordinary looking polynomial, but this is ",
  StyleBox["not", "TI"],
  " advised; doing so will result in something that could be numerically very \
unstable. That is, extreme loss of accuracy could result due to cancellation \
of digits. "
}], "Text",
  CellTags->{"S5.91.1", "1.4"}],

Cell["This loads the package. ", "MathCaption",
  CellTags->{"S5.91.1", "1.5"}],

Cell["<<NumericalMath`PolynomialFit`", "Input",
  CellLabel->"In[1]:= ",
  CellTags->"S5.91.1"],

Cell["Here is the cubic polynomial that fits the data. ", "MathCaption",
  CellTags->{"S5.91.1", "1.6"}],

Cell[CellGroupData[{

Cell["p = PolynomialFit[{1,4,9,16,25,36,49},3]", "Input",
  CellLabel->"In[2]:= ",
  CellTags->"S5.91.1"],

Cell[BoxData[
    InterpretationBox[\("FittingPolynomial[<>, "\[InvisibleSpace]3\
\[InvisibleSpace]"]"\),
      SequenceForm[ "FittingPolynomial[<>, ", 3, "]"],
      Editable->False]], "Output",
  CellLabel->"Out[2]= ",
  CellTags->"S5.91.1"]
}, Open  ]],

Cell["This evaluates the polynomial at 10. ", "MathCaption",
  CellTags->{"S5.91.1", "1.7"}],

Cell[CellGroupData[{

Cell["p[10]", "Input",
  CellLabel->"In[3]:= ",
  CellTags->"S5.91.1"],

Cell[BoxData[
    \(100.`\)], "Output",
  CellLabel->"Out[3]= ",
  CellTags->"S5.91.1"]
}, Open  ]],

Cell[TextData[{
  "This gives the ordinary form of the polynomial. Doing this and then \
replacing ",
  StyleBox["x", "MR"],
  " by some numerical value is not advised, especially for \
high\[Hyphen]degree polynomials. "
}], "MathCaption",
  CellTags->{"S5.91.1", "1.8"}],

Cell[CellGroupData[{

Cell["Expand[p[x]]", "Input",
  CellLabel->"In[4]:= ",
  CellTags->"S5.91.1"],

Cell[BoxData[
    \(\(-4.618527782440651`*^-14\) + 5.545564008002657`*^-14\ x + 
      0.9999999999999835`\ x\^2 + 1.3939466864738074`*^-15\ x\^3\)], "Output",\

  CellLabel->"Out[4]= ",
  CellTags->"S5.91.1"]
}, Open  ]]
},
FrontEndVersion->"4.0 for X",
ScreenRectangle->{{0, 800}, {0, 600}},
WindowSize->{520, 455},
WindowMargins->{{140, Automatic}, {Automatic, 72}},
StyleDefinitions -> "HelpBrowser.nb"
]


(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of 
the file.  The cache data will then be recreated when you save this file 
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{
  "S5.91.1"->{
    Cell[1717, 49, 148, 6, 70, "Subsection",
      CellTags->{"S5.91.1", "1.1"}],
    Cell[1868, 57, 616, 14, 70, "Text",
      CellTags->{"S5.91.1", "1.2"}],
    Cell[2487, 73, 995, 22, 70, "Text",
      CellTags->{"S5.91.1", "1.3"}],
    Cell[3485, 97, 71, 1, 70, "Caption",
      CellTags->"S5.91.1"],
    Cell[3559, 100, 698, 14, 70, "Text",
      CellTags->{"S5.91.1", "1.4"}],
    Cell[4260, 116, 79, 1, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.5"}],
    Cell[4342, 119, 95, 2, 70, "Input",
      CellTags->"S5.91.1"],
    Cell[4440, 123, 104, 1, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.6"}],
    Cell[4569, 128, 105, 2, 70, "Input",
      CellTags->"S5.91.1"],
    Cell[4677, 132, 243, 6, 70, "Output",
      CellTags->"S5.91.1"],
    Cell[4935, 141, 92, 1, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.7"}],
    Cell[5052, 146, 70, 2, 70, "Input",
      CellTags->"S5.91.1"],
    Cell[5125, 150, 87, 3, 70, "Output",
      CellTags->"S5.91.1"],
    Cell[5227, 156, 271, 7, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.8"}],
    Cell[5523, 167, 77, 2, 70, "Input",
      CellTags->"S5.91.1"],
    Cell[5603, 171, 209, 5, 70, "Output",
      CellTags->"S5.91.1"]},
  "1.1"->{
    Cell[1717, 49, 148, 6, 70, "Subsection",
      CellTags->{"S5.91.1", "1.1"}]},
  "1.2"->{
    Cell[1868, 57, 616, 14, 70, "Text",
      CellTags->{"S5.91.1", "1.2"}]},
  "1.3"->{
    Cell[2487, 73, 995, 22, 70, "Text",
      CellTags->{"S5.91.1", "1.3"}]},
  "1.4"->{
    Cell[3559, 100, 698, 14, 70, "Text",
      CellTags->{"S5.91.1", "1.4"}]},
  "1.5"->{
    Cell[4260, 116, 79, 1, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.5"}]},
  "1.6"->{
    Cell[4440, 123, 104, 1, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.6"}]},
  "1.7"->{
    Cell[4935, 141, 92, 1, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.7"}]},
  "1.8"->{
    Cell[5227, 156, 271, 7, 70, "MathCaption",
      CellTags->{"S5.91.1", "1.8"}]}
  }
*)

(*CellTagsIndex
CellTagsIndex->{
  {"S5.91.1", 6453, 196},
  {"1.1", 7664, 229},
  {"1.2", 7758, 232},
  {"1.3", 7847, 235},
  {"1.4", 7936, 238},
  {"1.5", 8026, 241},
  {"1.6", 8121, 244},
  {"1.7", 8217, 247},
  {"1.8", 8312, 250}
  }
*)

(*NotebookFileOutline
Notebook[{
Cell[1717, 49, 148, 6, 70, "Subsection",
  CellTags->{"S5.91.1", "1.1"}],
Cell[1868, 57, 616, 14, 70, "Text",
  CellTags->{"S5.91.1", "1.2"}],
Cell[2487, 73, 995, 22, 70, "Text",
  CellTags->{"S5.91.1", "1.3"}],
Cell[3485, 97, 71, 1, 70, "Caption",
  CellTags->"S5.91.1"],
Cell[3559, 100, 698, 14, 70, "Text",
  CellTags->{"S5.91.1", "1.4"}],
Cell[4260, 116, 79, 1, 70, "MathCaption",
  CellTags->{"S5.91.1", "1.5"}],
Cell[4342, 119, 95, 2, 70, "Input",
  CellTags->"S5.91.1"],
Cell[4440, 123, 104, 1, 70, "MathCaption",
  CellTags->{"S5.91.1", "1.6"}],

Cell[CellGroupData[{
Cell[4569, 128, 105, 2, 70, "Input",
  CellTags->"S5.91.1"],
Cell[4677, 132, 243, 6, 70, "Output",
  CellTags->"S5.91.1"]
}, Open  ]],
Cell[4935, 141, 92, 1, 70, "MathCaption",
  CellTags->{"S5.91.1", "1.7"}],

Cell[CellGroupData[{
Cell[5052, 146, 70, 2, 70, "Input",
  CellTags->"S5.91.1"],
Cell[5125, 150, 87, 3, 70, "Output",
  CellTags->"S5.91.1"]
}, Open  ]],
Cell[5227, 156, 271, 7, 70, "MathCaption",
  CellTags->{"S5.91.1", "1.8"}],

Cell[CellGroupData[{
Cell[5523, 167, 77, 2, 70, "Input",
  CellTags->"S5.91.1"],
Cell[5603, 171, 209, 5, 70, "Output",
  CellTags->"S5.91.1"]
}, Open  ]]
}
]
*)




(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)

