aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-06-21 17:25:27 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-06-21 17:25:27 +0200
commita71cf683b756e87bd8bcc2778fe45cc68d8c92e6 (patch)
tree49c5c3feedfe3851036f301877765f08f414580d /src
parentf0c404f1bbe16d052abae7254fad666196cdf46e (diff)
downloadfortran-assignment3-a71cf683b756e87bd8bcc2778fe45cc68d8c92e6.tar.gz
fortran-assignment3-a71cf683b756e87bd8bcc2778fe45cc68d8c92e6.zip
analytically compute integrals of test functions
Diffstat (limited to 'src')
-rw-r--r--src/functions.f9036
1 files changed, 32 insertions, 4 deletions
diff --git a/src/functions.f90 b/src/functions.f90
index 788de6b..b028c02 100644
--- a/src/functions.f90
+++ b/src/functions.f90
@@ -1,5 +1,8 @@
MODULE functions
+ real(kind=8), private, parameter :: poly_coeffs(11) = &
+ [-11.0, 15.6, -4.6, 22.5, 8.1, 5.1, -0.3, -8.0, 0.0, -9.9, 2.2]
+
CONTAINS
FUNCTION my_exp(x) result(y)
@@ -7,7 +10,7 @@ CONTAINS
real(kind=8) :: y
y = exp(x)
END FUNCTION my_exp
-
+
FUNCTION my_sin(x) result(y)
real(kind=8), intent(in) :: x
real(kind=8) :: y
@@ -17,9 +20,34 @@ CONTAINS
FUNCTION my_poly(x) result(y)
real(kind=8), intent(in) :: x
real(kind=8) :: y
- !! for the task some polynomial of order 10 should be tested...
- !! so to have a simple equation I chose Chebyshev polynomial
- y = cos(10 * acos(x))
+ integer(kind=4) :: i
+ y = sum(poly_coeffs(:) * [1.0_8, (x ** [(i, i = 1, 10)])])
END FUNCTION my_poly
+ FUNCTION my_exp_int(ibeg, iend) result(y)
+ real(kind=8), intent(in) :: ibeg, iend
+ real(kind=8) :: y
+ y = exp(iend) - exp(ibeg)
+ END FUNCTION my_exp_int
+
+ FUNCTION my_sin_int(ibeg, iend) result(y)
+ real(kind=8), intent(in) :: ibeg, iend
+ real(kind=8) :: y
+ y = -cos(iend) + cos(ibeg)
+ END FUNCTION my_sin_int
+
+ FUNCTION my_poly_int_indefinite(x) result(y)
+ real(kind=8), intent(in) :: x
+ real(kind=8) :: y
+ integer(kind=4) :: i, j
+ y = sum(poly_coeffs(:) * (1 / real([(j, j = 1, 11)])) * &
+ (x ** [(i, i = 1, 11)]))
+ END FUNCTION my_poly_int_indefinite
+
+ FUNCTION my_poly_int(ibeg, iend) result(y)
+ real(kind=8), intent(in) :: ibeg, iend
+ real(kind=8) :: y
+ y = my_poly_int_indefinite(iend) - my_poly_int_indefinite(ibeg)
+ END FUNCTION my_poly_int
+
END MODULE functions