where : ibrtses delphi

Delphi - polynominal fit


the source code of this page may not appear correctly in certain browsers
due to special characters. Have a look at the source of this HTML page
with notepad instead


A polynominal of nth order : p:=Sum(ai*x^i,i=0..n)=a0+a1*x+a2*x^2+ .. +an*x^n
shall be fitted to a bunch of m points (Xj,Yj). The square error shall be minimal:

We therefore derive the error to all variables, the aj's.
  1. calculate the square
  2. calculate the sum
  3. derive the terms with a0 in them, omit the others
Diff(error,a0):=Diff(Sum(Sqr(a0+a1*Xj+a2*Xj^2+ .. +an*Xj^n-Yj),j=1..m)=
  Diff(error,a0):=2*Sum(a0+a1*Xj+a2*Xj^2+.. an*Xj^n-Yj,j=1..m)=
and equally :

For the minimal error, the equations are each set to zero :

Calculating the sums :
Sum(p(Xj)-Yj,j = 1..m)=
   Sum(a0+a1*Xj+a2*Xj^2+ .. +an*Xj^n-Yj,j=1..m)=
Sum(Xj*(p(Xj)-Yj),j = 1..m)=
   Sum(a0*Xj+a1*Xj^2+a2*Xj^3+ .. +an*Xj^(n+1)-Xj*Yj,j=1..m)=

Ordering leaves n+1 equations for n+1 unknown. As equation system :
|m         Sum(Xj)       Sum(Xj^2)     .. Sum(Xj^n)    | |a0|    | Sum(Yj)     |
|Sum(Xj)   Sum(Xj^2)     Sum(Xj^3)     .. Sum(Xj^(n+1))| |a1|    | Sum(Xj*Yj)  |
|Sum(Xj^2) Sum(Xj^3)     Sum(Xj^4)     .. Sum(Xj^(n+2))|*|a2| =  | Sum(Xj^2*Yj)|
|..                                                    | |..|    | ..          |
|Sum(Xj^n) Sum(Xj^(n+1)) Sum(Xj^(n+2)) .. Sum(Xj^(2n)) | |an|    | Sum(Xj^n*Yj)|
Which can be solved


Feedback is welcome

sponsored links


last updated: 31.july.99

Copyright (99,2000) Ing.Büro R.Tschaggelar