Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

9: Least-Squares Approximation

( \newcommand{\kernel}{\mathrm{null}\,}\)

The method of least-squares is commonly used to fit a parameterized curve to experimental data. In general, the fitting curve is not expected to pass through the data points, making this problem substantially different from the one of interpolation.

We consider here only the most common situation: the fitting of a straight line through data with the same experimental error for all the data points. We assume that the data to be fitted are given by (xi,yi), with i=1 to n.

We write for the fitting curve

y(x)=αx+β.

The distance ri from the data point (xi,yi) and the fitting curve is given by

ri=yiy(xi)=yi(αxi+β).

A least-squares fit minimizes the sum of the squares of the ri ’s. This minimum can be shown to result in the most probable values of α and β.

We define

ρ=ni=1r2i=ni=1(yi(αxi+β))2

To minimize ρ with respect to α and β, we solve

ρα=0,ρβ=0

Taking the partial derivatives, we have

ρα=ni=12(xi)(yi(αxi+β))=0ρβ=ni=12(1)(yi(αxi+β))=0

These equations form a system of two linear equations in the two unknowns α and β, which is evident when rewritten in the form

αni=1x2i+βni=1xi=ni=1xiyiαni=1xi+βn=ni=1yi

These equations can be solved numerically, and MATLAB provides a built-in subroutine called polyfit.m. With the data in the vectors x and y, the MATLAB call

p= polyfit (x,y,1)

returns the values p(1)=α and p(2)=β, which can then be used to draw the fitting line.


This page titled 9: Least-Squares Approximation is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Jeffrey R. Chasnov via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?