Note: LaTeX isn't supported on this site. I'm not sure if there is a better way to write math equations other than to write them in code.
I'm writing a Fortran program to estimate pi through the summation of series:
A = Sum of a_i from i=1 to N
where
pi/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 ...
To compute pi through the series summation, the suggested approach is to set
a_i = (-1)^(i+1)/(2i-1)
To do this, I wrote the following Fortran program -
program cpi
double precision val, pi
integer i
num = 1000
val = 0
do i = 1, num
val = val + ((-1)**(i+1))/(2*i-1)
end do
pi = val
print *, 'Estimated Value of PI:', pi
end program cpi
When I run this program, the output is
Estimated Value of PI: 1.0000000000000000
I must have made a mistake (likely in the /(2*i-1)
). I new to Fortran and don't know what I did wrong.