Try out NAG Library functions

Explore NAG maths and stats routines with interactive demos
Function ID
D01GAF
Name
nagf_quad_1d_data
Description
One-dimensional integration of a function defined by data values only
Keywords
Gill–Miller quadrature | integration, non-adaptive | quadrature non-adaptive
This example evaluates the integral
0141+x2dx=π  
reading in the function values at 21 unequally spaced points.
The example data reflects that shown in the "Example" section of the routine documentation. You can change this here to try alternative inputs. The formatting will need to be kept as it is here, otherwise the program is likely to fail to run correctly.

Please note that incompatible data will however cause the example output to display an error message. These error messages are fully explained in the Routine document
    Program d01gafe

!     D01GAF Example Program Text

!     Mark 26 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: d01gaf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: ans, er
      Integer                          :: i, ifail, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: x(:), y(:)
!     .. Executable Statements ..
      Write (nout,*) 'D01GAF Example Program Results'

!     Skip heading in data file
      Read (nin,*)

      Read (nin,*) n
      Allocate (x(n),y(n))

      Read (nin,*)(x(i),y(i),i=1,n)

      ifail = -1
      Call d01gaf(x,y,n,ans,er,ifail)

      Select Case (ifail)
      Case (0)
        Write (nout,*)
        Write (nout,99999) 'Integral = ', ans, '     Estimated error = ', er
      Case (1)
        Write (nout,*)
        Write (nout,*) 'Less than 4 points supplied'
      Case (2)
        Write (nout,*)
        Write (nout,*) 'Points not in increasing or decreasing order'
      Case (3)
        Write (nout,*)
        Write (nout,*) 'Points not all distinct'
      End Select

99999 Format (1X,A,F7.4,A,F7.4)
    End Program d01gafe
The NAG Library
The world’s largest collection of robust, documented, tested and maintained numerical algorithms.
Learn more here or contact us for purchasing information