Interactive Educational Modules in
Scientific Computing

Least Squares Data Fitting

This module demonstrates fitting a polynomial to a set of data points using the method of least squares. For a given number of data points, a polynomial of relatively low degree tends to capture the general trend of the data, glossing over minor deviations, whereas a polynomial of higher degree follows the data more closely but with a more oscillatory curve. With a polynomial of sufficiently high degree (one less than the number of data points), the data can be fit exactly, but this is often undesirable if the data are noisy.

The user first clicks repeatedly on the graph to create a set of data points, or alternatively can select a pre-set example. The user then selects the degree of the polynomial to be fit to the data. The resulting polynomial is plotted on the graph, and its coefficients can be viewed in a separate window by clicking on View Polynomial. The polynomial is updated automatically whenever more data points are added or a new degree is selected. The user may select among two choices of fitting criteria: fitting y to x (residual measured vertically) or fitting x to y (residual measured horizontally).

Reference: Michael T. Heath, Scientific Computing, An Introductory Survey, 2nd edition, McGraw-Hill, New York, 2002. See Section 3.1, especially Example 3.2.

Developers: Nicholas Exner, Jeffrey Naisbitt, and Michael Heath