Supplied data

The data required for this project is in the Chapter 6 folder, Projects/MathsData.txt. The content of the file should be used within the application (copy and paste). If the data sets do not have the same number of elements, remove elements from the end of the set with the larger number of elements.

Let's look at the math required:

  • The equation of a straight line:

The equation is very simple:

y = mx + c, where m is the gradient and c is the intercept on the y axis

  • Gradient of the regression line:

The equation is as follows:

>

This may look hairy but it's quite simple, so long as the following rule is remembered:

 is not equal to 

So, what is the difference?

 means that it is the sum of x2 while  is the sum of x squared. Let's consider the following code as an example:

To save time at this point, it is worth performing the following calculations:

  • xy for each set, followed by ∑xy for each
  • x, y, x2, (x)2,  (the average of x), ; (the average of the y values)

The data is needed for the regression gradient and intercepts on the y value. After that is performed, it is simply a case of plugging in the numbers.

For example, y = 5.8907, x = 5, x2 = 7.5, (x)2 = 25, n = 4, xy = 8.8528

Moreover, none of the math from here on in is any harder than that.

  • Getting the intercepts

We already have the formula for the intercept on the y axis (c) by the equation, which is as follows:

Again, using the same data as earlier, the numbers slot in and give an answer of -0.0167.

Now, this is the intercept on y; however, we want the intercept on the x axis as well. To do this, we can say that we want to know the value of x when y = 0. The equation of the straight line is y = mx + c; therefore, to get x by itself, the equation will be as follows:

Simple!

  • Deviation must be known:

There are two more factors to be considered with the regression analysis-the standard deviation (better known as the error in the line) and the r2 value (the correlation coefficient; in other words, how good a straight line the line really is).

The two equations are a tad more difficult than before, but not by much.

First off, some more calculations will cover the standard deviation and the r2 calculations.

For the standard deviation, we will need to know (yexpt - ycalc)2. This can be done in line, as follows:

yexpt is the value from your experiment, ycalc can be read as mx + c (all three are known). Therefore, if we just plug in the numbers then square the result, we end up with (yexpt - ycalc)2. These numbers are then added together to give ∑(yexpt - ycalc)2.

In the r2 calculation, we will need to calculate  and then sum the results. This is easy, as are the parts in the denominator.

However, wait a second; there is a common item in both the deviation and r2 calculation, namely raising to the power ½. This is actually just another way of saying a square root.

It is now just a case of plugging in the numbers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset