David Little
Mathematics Department
Penn State University
Eberly College of Science
University Park, PA 16802
Office: 403 McAllister
Phone: (814) 865-3329
Fax: (814) 865-3735

Home Courses Math Links Resources Java Applets

Least Squares

The following applet can be used to find the least squares line corresponding to a collection of data. Simply enter the data and the slope, m, and y-intercept, b, of the proposed line that minimizes the sum of the square of the vertical distances between the data and the line. The applet automatically draws this line and calculates the distance between the line and the data. The user may also have the applet display the actual least squares line.

The values of m and b can be changed by simply typing a new value, such as "1.2345", "pi/2", "sqrt(5)+cos(3)", etc. You may also change these values by using the up/down arrow keys or dragging the corresponding point on the graph. To move the center of the graph, simply drag any point to a new location. To label the x-axis in radians (i.e. multiples of pi), click on the graph and press "control-r". To switch back, simply press "control-r" again.

To manually enter data, first select n, the number of data points. The y-coordinate of each point can be changed by dragging the corresponding point up or down. To change the x-coordinate, hold down the shift key while dragging the corresponding point left or right. Alternatively, the user may click on the data point and then type the coordinates in the appropriate text fields.

© 2010 David P. Little
Download this applet for off-line viewing (includes source code). The above applet uses the Java Math Expression Parser (JEP) developed by Singular Systems