Tutorial 11:  Data

by R. Dover, IMSA

Plotting

We'll name a list of points, and then of course, we'll do a couple of things with the plots.  Incidentally, you'll notice that this list of points is semi-random. ( It has no purpose that I know of.)  We have a list of lists.

onelist  =  {{1, 5},  {3, 8},  {3.2,  4.1},  {5.4,  
          8.7},  {8,  4.2},  {6.3,  1.1},  {9.2,  3.7},  {2.5,  
          7.2}}

ListPlot[onelist]

Let's improve/change that a bit.  Move the axes to the origin.  (Use the option "AxesOrigin -> {0,0}".)  Then make the points a little bigger.  (Another option:  PlotStyle -> PointSize[.02] or choose a size you like.)  Then join the points together.  (PlotJoined -> True)  Check out the options to see if you'd like to do anything else.  (Colors?)

Note that real data will often make "PlotJoined -> True" a lot more interesting and useful.    Be sure to clear onelist.

A table first...

This example and the resulting graph is a little more interesting since there is a pattern to the points.  First define a function a(n) = sin(n).

Now, name and create a table of ordered pairs (n, a(n)), where n is an integer from 1 to 50.  (You'll find that numerical values will be helpful here.)  Not much of pattern?

Use "ListPlot" on your table.  Still not much of a pattern?

Increase the integer range to extend from 1 to 300.  Plot this.  Then add another option:  AspectRatio -> 1/3.  How's the pattern?

Regression

Let's begin with some more data.

somedata  =   {{ .1,  3.1},  { .6,  3.7},  {1.4,  
          3.9},  {1.9,  3.2},  {2.3,  2.6},  {2.5,  2},  {2.7,  
          1.8},  {3,  1.2},  {3.1,   .5},  {3.6,  
          0},  {4,  - .3},  {4.2,  - .4},  {5,   .2},  {5.3,   .8},  {5.7,  1.4},  {6,  2.2}}

Use ListPlot to show this, naming the plot "graphdata".  Make the points big enough to see.

So how about a cubic?  The following command will fit your data as well as possible to a polynomial with constant, linear, quadratic, and cubic terms, where x is the variable.

func1  =  Fit[somedata,  {1,  x,  (x^2),  (x^3)},  x]

We need to see how reasonable this is.  Graph "func1" on the interval [0, 6], naming the plot "graph1".

We next want to show the two graphs together.  The "Show" command is necessary to put two graphs which required different commands (Plot and ListPlot) together.

Show[graphdata,  graph1]

Let's look at some trig now.  We'll do essentially the same thing, using Sin[x] and Cos[x] instead of some polynomial terms.  However, the constant term still looks reasonable.  We'll call this func2.

func2  =  Fit[somedata,  {1,  Sin[x],  Cos[x]},  x]

Creat the plot "graph2" of func2.

Show the graph of the data and graph2 together.

Then show all three graphs together.  (Color may be useful here. Go back and change graph1 or graph2.)  Which is better?