Program in fortran to find the value of integration of the function [(1-x^2)^1/2]*cosx by Trapezoidal rule
! Program in fortran to find the value of integration of the
! function [(1-x^2)^1/2]*cosx by Trapezoidal rule
write(*,*)'Enter the lower and upper limits respectively:'
read(*,*)a,b
Write(*,*)'Enter the number of sub intervals (n):'
read(*,*)n
sum=f(a)+f(b)
h=(b-a)/n
do i=1,n-1
sum=sum+2.0*f(a+i*h)
end do
sum=sum*h/2.0
write(*,11)sum
11 format(2x,'The value of the integration corrected upto six decimal places
is',f16.6)
end
! Program sub function
function f(x)
f=(sqrt(1-x*x))*cos(x)
return
end
! function [(1-x^2)^1/2]*cosx by Trapezoidal rule
write(*,*)'Enter the lower and upper limits respectively:'
read(*,*)a,b
Write(*,*)'Enter the number of sub intervals (n):'
read(*,*)n
sum=f(a)+f(b)
h=(b-a)/n
do i=1,n-1
sum=sum+2.0*f(a+i*h)
end do
sum=sum*h/2.0
write(*,11)sum
11 format(2x,'The value of the integration corrected upto six decimal places
is',f16.6)
end
! Program sub function
function f(x)
f=(sqrt(1-x*x))*cos(x)
return
end
Comments
Post a Comment