Curve Fitting/Regression

The conversion of data to a working equation is one of the hallmarks of what mathematics can do but usually we spend not near enough time on this concept. Every time you do an exercise from a textbook and you are given some equation or function you are really looking at the result of a curve fitting to data. particularly when you are doing an application type problem. This tutorial will help you navigate how to take a set of data and turn it into a working function (both linear and quadratic).

For this example consider the following set of data (t,N) where t is time and N is some value we have measured.

Data Entry

Our first task is to enter the data into our calculator and see what it looks like. To do this press the [STAT] button to bring up the data editor. Choose option #1-Edit.

The x,y information is then entered into the variables L1,L2 or more depending on how much data you want to enter. We will be entering the t data into L1 and the N data into L2.

You can use the arrow keys to navigate to the position you want, enter your data, and press [Enter] after each entry before moving to the next column of data. Make sure you have the same number of entries in such column to avoid errors. A sample of what this data entered looks like is below.

Plotting the Data

Once the data is entered it is usually a good idea to take a look at it so we can decide what kind of curve will be the best fit. To do this we will use the STAT PLOT feature to show the data on a graph.

To turn on the stat plots press [2nd] and then [y=].

To use the first plot press [Enter] to access the plot setup. Make sure that the plot is turned on, and the x-list and y-list match the list variables you entered the data into. My setup is shown below.

Before we graph the data we need to set the window ranges that will best show my data points. Looking at the input and output values of the table it is easy to see how the x-min, x-max and y-min, y-max values should be defined. My setup is show below.

Once your window is set you and then press [Graph] to see what your data set looks like.

Fitting a Linear Curve

Based on the plot above it's not completely unreasonable to think that a straight line would be a decent fitting curve for this set of data. To find the equation of that line we are going to go back to the [Stat] button this time to the CALC menu. We will find that #4 is the function for LinReg (ax+b).

When we press enter we are returned to the home screen with the LinReg(ax+b) waiting for the parameters of our regression. For our purposes we need to tell it to use the L1 and L2 lists as well we'd like to have it store that equation in Y1 so we can see how this graphs compared to our data.

To get the variables it needs we to look at our number keys from 1 to 6. If you look above them you will see that their second function is the L variable. We also need a comma to separate them. So press [2nd]->1 and then [,] and then [2nd]->2 to get the L1 and L2. Then, press [,] again and press [Vars], go to the Y-VARS menu, selection Function and select Y1. When you are done it should look like this

When you are done press [Enter] and it will find the linear regression. It will display for you the a and b coefficients for y=ax+b as well as store it in your Y1 position to graph.

And if you hit the [Graph] button you will see how you line compares to the data.

We can see this is an OK fit but maybe we want to try a quadratic regression to try and get an even better fit.

Quadratic Regression

With the data stored we can easily now try a Quadratic Regression to see if it works any better. Once again hit the [Stat] button and go this time to choice #5 QuadReg.

We will give it the same variables again this time EXCEPT we want to put this equation in the Y2 position.

Once we press [Enter] we will see our coefficients again.

It will be stored in Y2.

And it will graph along with our data set and out linear regression line.