![]() |
Collection of points from a random data set. Source |
![]() |
The model fits the data. Source |
![]() |
Equations. Source |
Your challenge is to create a problem that given a list of points, is able to print out the a and b values of the linear regression. Here is a suggestion for how to represent your initial set of x-y pairs.
Another tip is to break apart your summation calculations into individual pieces as I did in the spreadsheet and to then combine all the parts at the end for when you are calculating your a & b values. This will make it easier to organize the program.

You could also try to download graphing software for use in your Java programs as outlined in this tutorial.
Extension #1: In the real world, a line is not going to fit every data set. Quadratic curves are some of the most recognizable objects in mathematics, and can also be fit to data sets.
![]() |
Whoa! Source |
You may remember the strategy for solving these kinds of linear systems: continuously eliminating variables until you solve for one, then another until you solve the system. When we did the problems by hand, we strategically eliminated variables which matched up well between the equations. Here we don't need to worry about cherry-picking a particular strategy because the computer won't mind performing what we would consider difficult operations by hand. Therefore, the whole process lends itself well to algorithmic programming.
![]() |
Strategy to solve systems of linear equations. Source |
As before, you can test your final values for the quadratic equation with the list of points in an online graphing calculator.
Good Luck!
No comments:
Post a Comment