Inexperience
Programmer
I am very new to fortran and I have been assigned to write a Simpsons 1/3 function. Below is what I have come up with but it is outputting the area as 0. All help is greatly appreciated.
Program test
IMPLICIT NONE
REAL :: n, simp13, Simpson13
INTEGER, DIMENSION(10) :: V
INTEGER :: h
V = (/4,5,6,7,8,9,10,11,12,13/)
h = 1
n = 9
Simp13=Simpson13(V,h,n)
WRITE (*,*) 'The area is:', Simp13
Pause
End Program test
!*******************************************
REAL FUNCTION Simpson13 (V,h,n)
IMPLICIT NONE
INTEGER, INTENT(IN) :: V
INTEGER, INTENT(IN) :: h
Real :: i,Vodd,Veven,n
Vodd=0
Veven=0
DO i=1,((n-2)/2)
Vodd=Vodd+V(2*i-1)
END DO
Do i=1,((n-2)/2)
Veven=Veven+V(2*i)
END DO
Simpson13=(h/3)*(V(1)+4*Vodd+2*Veven+V)
END FUNCTION Simpson13
Program test
IMPLICIT NONE
REAL :: n, simp13, Simpson13
INTEGER, DIMENSION(10) :: V
INTEGER :: h
V = (/4,5,6,7,8,9,10,11,12,13/)
h = 1
n = 9
Simp13=Simpson13(V,h,n)
WRITE (*,*) 'The area is:', Simp13
Pause
End Program test
!*******************************************
REAL FUNCTION Simpson13 (V,h,n)
IMPLICIT NONE
INTEGER, INTENT(IN) :: V
INTEGER, INTENT(IN) :: h
Real :: i,Vodd,Veven,n
Vodd=0
Veven=0
DO i=1,((n-2)/2)
Vodd=Vodd+V(2*i-1)
END DO
Do i=1,((n-2)/2)
Veven=Veven+V(2*i)
END DO
Simpson13=(h/3)*(V(1)+4*Vodd+2*Veven+V)
END FUNCTION Simpson13