[MAP Logo]

Materials Algorithms Project
Program Library



Subroutine MAP_UTIL_POLY

  1. Provenance of code.
  2. Purpose of code.
  3. Specification.
  4. Description of subroutine's operation.
  5. References.
  6. Parameter descriptions.
  7. Error indicators.
  8. Accuracy estimate.
  9. Any additional information.
  10. Example of code
  11. Auxiliary subroutines required.
  12. Keywords.
  13. Download source code.
  14. Links.

Provenance of Source Code

H.K.D.H. Bhadeshia,
Phase Transformations Group,
Department of Materials Science and Metallurgy,
University of Cambridge,
Cambridge, U.K.

Added to MAP: June 1999.

Top | Next

Purpose

To calculate a least squares fit of a second order polynomial to an (x,y) data set.

Top | Next | Prev

Specification

Language:FORTRAN
Product form:Source code

SUBROUTINE MAP_UTIL_POLY(X,Y,NPNT,A)

DOUBLE PRECISION X(6),Y(6),A(3),COEF(3,3)
INTEGER NPNT

Top | Next | Prev

Description

MAP_UTIL_POLY calculates a least squares fit of a second order polynomial to an (x,y) data set. The input data consists of sets of x,y pairs. The routine calculates the coefficients of the polynomial:

y = A1 + A2x + A3(x*x)

which give a least squares fit to the input data. These coefficients are returned to the calling routine.

Top | Next | Prev

References

None.

Top | Next | Prev

Parameters

Input parameters

X - real array of dimension not less than NPNT.
X contains the x co-ordinates of the data set.

Y - real array of dimension not less than NPNT.
Y contains the corresponding y co-ordinates of the data set.

NPNT - integer
NPNT is the number of x,y pairs.

Output parameters

A - real array of dimension 3
A(1), A(2) and A(3) are the coefficients A1, A2 and A3 of the fitted polynomial, as described above.

Top | Next | Prev

Error Indicators

None.

Top | Next | Prev

Accuracy

No information supplied.

Top | Next | Prev

Further Comments

The size of the arrays X and Y are currently set to 6 but should be set to a value not less than NPNT for use with values of NPNT>6.

Top | Next | Prev

Example

1. Program text

      IMPLICIT NONE
      DOUBLE PRECISION A(3),X(6),Y(6)
      INTEGER L1,NPNT
C
      WRITE(*,*) 'Input number of data sets:'
      READ (*,*) NPNT
      WRITE(*,*) 'Input x,y pairs:'
      DO 100 L1=1,NPNT
         READ(*,*) X(L1),Y(L1)
  100 CONTINUE
      CALL MAP_UTIL_POLY(X,Y,NPNT,A)
      WRITE(*,1) A(1),A(2),A(3)
      STOP
    1 FORMAT(/'A(1)=',F8.3/'A(2)=',F8.3/'A(3)=',F8.3)
      END

2. Program data

 Input number of data sets:
 6
 Input x,y pairs:
 0.761 0.302
 0.809 0.332
 0.857 0.332
 0.905 0.306
 0.952 0.222
 1.000 0.055

3. Program results

A(1)=  -6.860
A(2)=  17.277
A(3)= -10.351

Top | Next | Prev

Auxiliary Routines

None.

Top | Next | Prev

Keywords

least squares regression, least squares fit, polynomial

Top | Next | Prev

Download

Download source code

Top | Prev


MAP originated from a joint project of the National Physical Laboratory and the University of Cambridge.

MAP Website administration / map@msm.cam.ac.uk

Top | Index | MAP Homepage Valid HTML 3.2!