MOM6
polynomial_functions.F90
Go to the documentation of this file.
2 !==============================================================================
3 !
4 ! This file is part of MOM.
5 !
6 ! Date of creation: 2008.06.12
7 ! L. White
8 !
9 ! This module contains routines that handle polynomials.
10 !
11 !==============================================================================
12 
13 implicit none ; private
14 
16 
17 ! -----------------------------------------------------------------------------
18 ! This module contains the following routines
19 ! -----------------------------------------------------------------------------
20 contains
21 
22 ! -----------------------------------------------------------------------------
23 ! Pointwise evaluation of a polynomial
24 ! -----------------------------------------------------------------------------
25 real function evaluation_polynomial( coefficients, nb_coefficients, x )
26 ! -----------------------------------------------------------------------------
27 ! The polynomial is defined by the coefficients contained in the
28 ! array of the same name, as follows: C(1) + C(2)x + C(3)x^2 + C(4)x^3 + ...
29 ! where C refers to the array 'coefficients'.
30 ! The number of coefficients is given by nb_coefficients and x
31 ! is the coordinate where the polynomial is to be evaluated.
32 !
33 ! The function returns the value of the polynomial at x.
34 ! -----------------------------------------------------------------------------
35 
36  ! Arguments
37  real, dimension(:), intent(in) :: coefficients
38  integer, intent(in) :: nb_coefficients
39  real, intent(in) :: x
40 
41  ! Local variables
42  integer :: k
43  real :: f ! value of polynomial at x
44 
45  f = 0.0
46  do k = 1,nb_coefficients
47  f = f + coefficients(k) * ( x**(k-1) )
48  end do
49 
51 
52 end function evaluation_polynomial
53 
54 ! -----------------------------------------------------------------------------
55 ! Exact integration of polynomial of degree n
56 ! -----------------------------------------------------------------------------
57 real function integration_polynomial( xi0, xi1, C, n )
58 ! -----------------------------------------------------------------------------
59 ! Exact integration of a polynomial of degree n over the interval [xi0,xi1].
60 ! The array of coefficients (C) must be of size n+1, where n is the degree of
61 ! the polynomial to integrate.
62 ! -----------------------------------------------------------------------------
63 
64  ! Arguments
65  real, intent(in) :: xi0, xi1
66  real, dimension(:), intent(in) :: C
67  integer, intent(in) :: n
68 
69  ! Local variables
70  integer :: k
71  real :: integral
72 
73  integral = 0.0
74 
75  do k = 1,(n+1)
76  integral = integral + c(k) * (xi1**k - xi0**k) / real(k)
77  end do
78 !
79 !One non-answer-changing way of unrolling the above is:
80 ! k=1
81 ! integral = integral + C(k) * (xi1**k - xi0**k) / real(k)
82 ! if (n>=1) then
83 ! k=2
84 ! integral = integral + C(k) * (xi1**k - xi0**k) / real(k)
85 ! endif
86 ! if (n>=2) then
87 ! k=3
88 ! integral = integral + C(k) * (xi1**k - xi0**k) / real(k)
89 ! endif
90 ! if (n>=3) then
91 ! k=4
92 ! integral = integral + C(k) * (xi1**k - xi0**k) / real(k)
93 ! endif
94 ! if (n>=4) then
95 ! k=5
96 ! integral = integral + C(k) * (xi1**k - xi0**k) / real(k)
97 ! endif
98 !
99  integration_polynomial = integral
100 
101 end function integration_polynomial
102 
103 end module polynomial_functions
real function, public integration_polynomial(xi0, xi1, C, n)
real function, public evaluation_polynomial(coefficients, nb_coefficients, x)