next up previous index
Next: E210 Polynomial Splines Up: CERNLIB Previous: E201 Least Squares

E208 Least Squares Polynomial Fit

Routine ID: E208
Author(s): E. KeilLibrary: KERNLIB
Submitter: B. SchorrSubmitted: 01.12.1969
Language: FortranRevised: 27.11.1984

OBSOLETE

Please note that this routine has been obsoleted in CNL 218. Users are advised not to use it any longer and to replace it in older programs. No maintenance for it will take place and it will eventually disappear.
Suggested replacement: RLSQPM (E201)

Subroutine LSQ fits a polynomial of degree m-1 to n equally-weighted data points (xi,yi ). The computed coefficients aj of the fitted polynomial have values which minimize

i=1n( yi-∑j=1majxij-1) 2.

For the case m=2 (straight line fit), subroutine LLSQ is faster and easier to use than LSQ.

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

Structure:

SUBROUTINE subprograms
User Entry Names: LSQ, LLSQ
Files Referenced: Printer
External References: RVSUM (F002), RSEQN, DSEQN (F012), KERMTR (N001), ABEND (Z035)

Usage:

    CALL LSQ(N,X,Y,M,A)
    CALL LLSQ(N,X,Y,A1,A2,IFAIL)
N
( INTEGER) Number n of data points.
X
( REAL) One-dimensional array. X(i) must be equal to the data coordinate xi ,
(i=1,2,...,N) .
Y
( REAL) One-dimensional array. Y(i) must be equal to the observed value yi ,
(i=1,2,...,N) .
M
( INTEGER) On entry, M must be equal to the number m of coefficients of the polynomial to be fitted. On exit, the value of M may differ from this (see Error Handling).
A
( REAL) One-dimensional array. On exit from LSQ, A(j) is equal to the coefficient of xj-1 in the fitted polynomial, (j=1,2,...,M) .
A1,A2
( REAL) On exit from LLSQ, A1 and A2 are equal to the coefficients of the fitted straight line a1+a2x .
IFAIL
( INTEGER) On exit from LLSQ, IFAIL is equal to -2 if N < 2 , to -1 if the matrix of normal equations is numerically singular, and to zero otherwise.

Method:

Normal equations.

Error handling:

Error E208.1: M<1 or M>N or M>20 (subroutine LSQ). M is replaced by zero.
Error E208.2: The normal equations matrix is numerically singular (subroutine LSQ).
For each error, a message is printed unless subroutine KERSET (N001) has been called.

Notes:

On computers other than Cray and CDC double-precision arithmetic is used internally.

E210



next up previous index
Next: E210 Polynomial Splines Up: CERNLIB Previous: E201 Least Squares


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