aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-06-21 13:22:58 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-06-21 13:22:58 +0200
commit00e4d345ac3a40e7d1d18df7cf751833cd608612 (patch)
tree94e22d92a6dd758184797a66a150d2e5d21ab3f2 /src
parent7d28fe599e1a5498a7e86dc04fa207cab11559ac (diff)
downloadfortran-assignment3-00e4d345ac3a40e7d1d18df7cf751833cd608612.tar.gz
fortran-assignment3-00e4d345ac3a40e7d1d18df7cf751833cd608612.zip
compozite newton-cotes integration
Diffstat (limited to 'src')
-rw-r--r--src/quadratures.f9014
1 files changed, 12 insertions, 2 deletions
diff --git a/src/quadratures.f90 b/src/quadratures.f90
index a3f869f..9be7517 100644
--- a/src/quadratures.f90
+++ b/src/quadratures.f90
@@ -45,9 +45,13 @@ CONTAINS
real(kind=8), intent(in) :: iend
procedure(funint) :: fun
integer(kind=4), intent(in) :: p
- real(kind=8) :: val
+
+ real(kind=8) :: val, subinterval_width, qbeg, qend
procedure(quadrature), pointer :: quad
+ integer(kind=8) :: i
+
+ subinterval_width = (iend - ibeg) / subintervals
SELECT CASE (p)
CASE (:-1)
@@ -63,7 +67,13 @@ CONTAINS
END SELECT
! compute integral using quadrature pointed by quad
- val = quad(ibeg, iend, fun)
+ val = 0
+
+ DO i = 1, subintervals
+ qend = ibeg + i * subinterval_width
+ qbeg = ibeg + (i - 1) * subinterval_width
+ val = val + quad(qbeg, qend, fun)
+ END DO
END FUNCTION newton_cotes
FUNCTION rectangle(qbeg, qend, fun) result(val)