next up previous index
Next: E208 Least Squares Up: CERNLIB Previous: E106 Binary Search

E201 Least Squares Polynomial Fit

Routine ID: E201
Author(s): K.S. KölbigLibrary: MATHLIB
Submitter: Submitted: 01.12.1994
Language: FortranRevised:

Subroutine subprograms RLSQPM and DLSQPM fit a polynomial

pm(x) = ∑j=0majxj

of degree m to n equally-weighted data points (xi,yi ). The calculated coefficients aj are such that

Sm2 = ∑i=1n(yi-pm(xi))2 = min.

Subroutine subprograms RLSQP1 and DLSQP1 fit a straight line p1(x) = a0+a1x to n such points.

Subroutine subprograms RLSQP2 and DLSQP2 fit a parabola p2(x) = a0+a1x+a2x2 to n such points.

An estimate s = Sm2/(n-m-1)

of the standard deviation σ is calculated.

On CDC and Cray computers, the double-precision versions DLSQPM, DLSQP1 and DLSQP2 are not available.

Structure:

SUBROUTINE subprograms
User Entry Names: RLSQPM, RLSQP1, RLSQP2, DLSQPM, DLSQP1, DLSQP2
External References: RVSET, DVSET, DVSUM, DVMPY (F002), DSEQN (F012)

Usage:

For t=R (type REAL), t=D (type DOUBLE PRECISION),

    CALL tLSQPM(N,X,Y,M,A,SD,IFAIL)
    CALL tLSQP1(N,X,Y,A0,A1,SD,IFAIL)
    CALL tLSQP2(N,X,Y,A0,A1,A2,SD,IFAIL)
N
( INTEGER) Number n of data points.
X
(type according to t) One-dimensional array of length ≥N . On entry, X(i) contains the abscissas xi, (i=1,2,...,n) .
Y
(type according to t) One-dimensional array of length ≥N . On entry, Y(i) contains the ordinates yi, (i=1,2,...,n) .
M
( INTEGER) Degree m of the polynomial to be fitted.
A
(type according to t) One-dimensional array of dimension (0:d), where d ≥M . Contains, on exit, in A(j) the coefficients aj, (j = 0,1,...,m) .
A0,A1,A2
(type according to t) Contain, on exit, the coefficients a0 , a1 for p1(x)=a0+a1x or a0,a1,a2 for p2(x)=a0+a1x+a2x2 , respectively.
SD
(type according to t) Contains, on exit, the estimate s.
IFAIL
( INTEGER) Error flag.
= 0: Normal case,
= 1: N ≤1 or M<0 or M ≥N or M>20 ,
= -1: The matrix of normal equations is numerically singular.
In the case IFAIL ≠0 : M=0 , A(j)=0 and A0=A1=A2=0 on exit.

Method:

The normal equations are solved. On computers other than CDC or Cray, double-precision mode arithmetic is used internally for RLSQPM, RLSQP1 and RLSQP2.

Notes:

Meaningful results can usually be obtained only for small values of m (typically <10 ).

References:

  1. D.H. Menzel, Fundamental formulas of physics, v. 1, (Dover, New York 1960) 116--122.

E208



next up previous index
Next: E208 Least Squares Up: CERNLIB Previous: E106 Binary Search


Janne Saarela
Mon Apr 3 15:06:23 METDST 1995