A bit about ListPlot[] and Fit[]

Just so you see how to collect and display results, the ListPlot function generates the pictures.
It takes as data {x,y} points in the form  { {x1,y1}, {x2,y2}, ... }.  Everything else is an option.

Options[ListPlot]

{AspectRatio1/GoldenRatio, AxesAutomatic, AxesLabelNone, AxesOrigin ... , Prolog {}, RotateLabelTrue, TextStyle$TextStyle, TicksAutomatic}

? ListPlot

ListPlot[{y1, y2, ... }] plots a list of values. The x coordinates for each point are taken to ... {{x1, y1}, {x2, y2}, ... }] plots a list of values with specified x and y coordinates. More…

Here's how you might generate a bunch of numbers to plot.  

data = Table[ {i, 2i - 1}, {i, 1, 10}]

{{1, 1}, {2, 3}, {3, 5}, {4, 7}, {5, 9}, {6, 11}, {7, 13}, {8, 15}, {9, 17}, {10, 19}}

data//MatrixForm

( 1    1  )            2    3            3    5            4    7            5 ...   9            6    11            7    13            8    15            9    17            10   19

Or, if you have all the x's and then all the y's, you can flip them around.

Transpose[data]

{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 3, 5, 7, 9, 11, 13, 15, 17, 19}}

Transpose[data]//MatrixForm

( 1    2    3    4    5    6    7    8    9    10 )            1    3    5    7    9    11   13   15   17   19

Generating the plot is just

ListPlot[data]

[Graphics:../HTMLFiles/index_156.gif]

⁃Graphics⁃

Though there are many options you can apply.

RowBox[{pointPlot, =, RowBox[{ListPlot, [, RowBox[{data, ,, , AxesLabel {" ... owBox[{RowBox[{PointSize, [, 0.02, ]}], ,, RGBColor[1, 0, 0]}], }}]}]}], , , ]}]}]

[Graphics:../HTMLFiles/index_159.gif]

⁃Graphics⁃

To find an equation that matches the points, you can use Fit[], which also has a bunch of variations.  For a polynomial fit,

Fit[data, {1, x, x^2, x^3}, {x}]

RowBox[{RowBox[{-, 1.}], +, RowBox[{2.,  , x}], +, RowBox[{1.78569*10^-16,  , x^2}], +, RowBox[{1.01033*10^-17,  , x^3}]}]

which gives some tiny numbers due to round-off errors.  But we can get rid of them with Chop.

bestFit = Chop[Fit[data, {1, x, x^2, x^3}, {x}]]

RowBox[{RowBox[{-, 1.}], +, RowBox[{2.,  , x}]}]

Here's what that function looks like.

linePlot = Plot[bestFit, {x, 0, 12}]

[Graphics:../HTMLFiles/index_166.gif]

⁃Graphics⁃

And here are both plots shown together with a label.

Show[pointPlot, linePlot, Graphics[Text["Dots and a line.",  ... PlotRange {{0, 12}, {0, 20}}, PlotLabel->"Cool, eh?"]

[Graphics:../HTMLFiles/index_169.gif]

⁃Graphics⁃


Created by Mathematica  (September 29, 2004)