forked from miladsade96/FCS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpson_rule.f90
More file actions
27 lines (25 loc) · 831 Bytes
/
simpson_rule.f90
File metadata and controls
27 lines (25 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
! Created by EverLookNeverSee@GitHub on 4/23/20.
! This program integrate a function numerically
! using simpson's rule.
! Simpson's Rule:
! https://en.wikipedia.org/wiki/Simpson's_rule
program simpson_rule
implicit none
! declaring counter and number of panels variables
integer :: i, n = 100
! declaring inerval and other variables
real :: a = 1.0, b = 4.0, sum = 0.0, h, x
h = (b - a) / n
sum = sum + (a ** 3 * exp(-a ** 3) + &
b ** 3 * exp(-b ** 3) + 4.0 * (b - h) ** 3&
* exp(-(b - h) ** 3))
x = a + h
do i = 2, n-2, 2
sum = sum + 4.0 * (x ** 3 * exp(-x ** 3))
x = x + h
sum = sum + 2.0 * (x ** 3 * exp(-x ** 3))
x = x + h
end do
sum = h / 3.0 * sum
print *, "The result of integration is:", sum
end program simpson_rule