script for generating data from integrator program
[AGH_fortran_course_solution3.git] / src / functions.f90
blob509cecf0fe5df6a9c44e7a75858e24fc326b0077
1 ! Copyright 2019 Wojciech Kosior
3 ! This is free and unencumbered software released into the public domain.
5 ! Anyone is free to copy, modify, publish, use, compile, sell, or
6 ! distribute this software, either in source code form or as a compiled
7 ! binary, for any purpose, commercial or non-commercial, and by any
8 ! means.
10 ! In jurisdictions that recognize copyright laws, the author or authors
11 ! of this software dedicate any and all copyright interest in the
12 ! software to the public domain. We make this dedication for the benefit
13 ! of the public at large and to the detriment of our heirs and
14 ! successors. We intend this dedication to be an overt act of
15 ! relinquishment in perpetuity of all present and future rights to this
16 ! software under copyright law.
18 ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 ! IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 ! OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ! ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 ! OTHER DEALINGS IN THE SOFTWARE.
26 ! For more information, please refer to <http://unlicense.org/>
28 MODULE functions
30 real(kind=8), private, parameter :: poly_coeffs(11) = &
31 [-11.0, 15.6, -4.6, 22.5, 8.1, 5.1, -0.3, -8.0, 0.0, -9.9, 2.2]
33 INTERFACE
34 FUNCTION analytical_integral(ibeg, iend) result(y)
35 real(kind=8), intent(in) :: ibeg, iend
36 real(kind=8) :: y
37 END FUNCTION analytical_integral
38 END INTERFACE
40 CONTAINS
42 FUNCTION my_exp(x) result(y)
43 real(kind=8), intent(in) :: x
44 real(kind=8) :: y
45 y = exp(x)
46 END FUNCTION my_exp
48 FUNCTION my_sin(x) result(y)
49 real(kind=8), intent(in) :: x
50 real(kind=8) :: y
51 y = sin(x)
52 END FUNCTION my_sin
54 FUNCTION my_poly(x) result(y)
55 real(kind=8), intent(in) :: x
56 real(kind=8) :: y
57 integer(kind=4) :: i
58 y = sum(poly_coeffs(:) * [1.0_8, (x ** [(i, i = 1, 10)])])
59 END FUNCTION my_poly
61 FUNCTION my_exp_int(ibeg, iend) result(y)
62 real(kind=8), intent(in) :: ibeg, iend
63 real(kind=8) :: y
64 y = exp(iend) - exp(ibeg)
65 END FUNCTION my_exp_int
67 FUNCTION my_sin_int(ibeg, iend) result(y)
68 real(kind=8), intent(in) :: ibeg, iend
69 real(kind=8) :: y
70 y = -cos(iend) + cos(ibeg)
71 END FUNCTION my_sin_int
73 FUNCTION my_poly_int_indefinite(x) result(y)
74 real(kind=8), intent(in) :: x
75 real(kind=8) :: y
76 integer(kind=4) :: i, j
77 y = sum(poly_coeffs(:) * (1 / real([(j, j = 1, 11)])) * &
78 (x ** [(i, i = 1, 11)]))
79 END FUNCTION my_poly_int_indefinite
81 FUNCTION my_poly_int(ibeg, iend) result(y)
82 real(kind=8), intent(in) :: ibeg, iend
83 real(kind=8) :: y
84 y = my_poly_int_indefinite(iend) - my_poly_int_indefinite(ibeg)
85 END FUNCTION my_poly_int
87 END MODULE functions