Linear Least-Squares Data-Fitting Utility

This page contains a linear least-squares data-fitting utility. The function to be fit to the data is a polynomial expression of degree four or less. It is written in JavaScript, so make sure that JavaScript is enabled in your browser.

References:

Author:   Stephen Nash,   George Mason University
From the book "Numerical Methods and Software" by
D. Kahaner, C. Moler, and S. Nash
Prentice Hall, 1988

Dongarra, J. J.;   J.R. Bunch;   C.B. Moler;   and G.W. Stewart.
          "LINPACK User's Guide"
          SIAM, Philadelphia
          1979

The utility posted on this page is based on the program SQRLS written by Stephen Nash. SQRLS is a top-level program that controls several sub-routines from the LINPACK collection. The original programs were written in FORTRAN and have been translated to Javascript here. Although all care has been taken to ensure that the sub-routines were translated accurately, some errors may have crept into the translation. These errors are mine; the original FORTRAN routines have been thoroughly tested and work properly. Please report any errors to the webmaster.


For background on linear, least-squares data fitting, please visit the Background and Worked Example page (opens in a new window).

HOW TO USE THIS UTILITY
Enter the data pairs below, and specify the degree of the polynomial to be fit to the data.
Then click the "Solve" button.
The results are output below.
Always check the value of the rank of the coefficient matrix after running this utility. The rank should be 1   +   the degree of polynomial selected. For example, if a polynomial of degree 2 was selected, the rank should be 3; if a polynomial of degree 3 was selected, the rank should be 4; etc. If the rank is less than this value, the solution is most likely meaningless.

This utility accepts up to twenty data pairs, (x i  , y i  ). Enter the data pairs below. Ensure that the checkbox to the left of each data pair is checked; otherwise, this utility will not include the values for that data pair in its calculations.

x1 y1           x2 y2
x3 y3       x4 y4
x5 y5       x6 y6
x7 y7       x8 y8
x9 y9       x10 y10
x11 y11       x12 y12
x13 y13       x14 y14
x15 y15       x16 y16
x17 y17       x18 y18
x19 y19       x20 y20

Specify the degree of the polynomial to be fit to the data by checking the radio button under the appropriate term. For example, if you are fitting a straight line to the data, select the radio button under the "d x" term. Once you have selected the appropriate button, click the "Solve" button, and the values for the constants will be displayed below.
a x 4   +   b x 3   +   c x 2   +   d x   +   e
         

The results are:
a   b   c   d   e
       

Number of Recognized Data Pairs:

Rank of Coefficient Matrix:

The residuals are:

r 1
r 2
r 3
r 4
r 5
r 6
r 7
r 8
r 9
r 10
r 11
r 12
r 13
r 14
r 15
r 16
r 17
r 18
r 19
r 20

Return to Math Functions Page

Return to Thothworks Home Page