Comp Sci Calculating pi using Riemann Sum and Fortran77

AI Thread Summary
The discussion focuses on calculating pi using a Riemann Sum with n=40,000,000, specifically through the antiderivative of 4/(1+x^2) from 0 to 1. Participants emphasize the importance of understanding the integration process and suggest looking up the standard function related to the derivative. Assistance is requested for programming in Fortran77, with suggestions to share code snippets for troubleshooting. There is also a debate on the necessity of using Fortran77 versus other programming languages or even Excel for obtaining results. Overall, the thread highlights the integration and programming challenges involved in solving the assignment.
ncp1044
Messages
8
Reaction score
0
My assignment: Solve for pi using a Riemann Sum with n= 40,000,000. The function is the antiderivate of 4/(1+x^2) dx. The bounds are from 0 to 1. Solving this gives you pi.

Anyone know how to do this? Preferably with fortran77?
 
Physics news on Phys.org
A priori, homework and assignment question should be posted in the appropriate section, namely:
https://www.physicsforums.com/forumdisplay.php?f=158

Having said that, I'll look at your problem in that light. You will work out the function whose derivative is 4/(1+x^2). You do this by integration, and alternatively, it is a standard function that you can look up in references.
If you are not sure if this is correct, post your finding and we will be glad to confirm it.

You can find out about the Riemann Sum by googling just that. If you still do not understand what it is, post again.

The program in Fortran is basically a summation process with evaluation of the derivative (4/(1+x^2) at given intervals. The sum, if done correctly, should be your estimate of pi.
 
I understand the calculus part of the problem; I just need help with the programming part. I can do the differentiation and I know how to do a Riemann Sum by hand, assuming that the number of intervals is small. I'm no good at programming so if anyone knows, some help would be appreciated.
 
Did you take a Fortran course, or is this assignment part of the course?
Can you show us a few lines you wrote, and try to compile it. This way, we can see where your problem lies, if there is any?

Typically, you would write the main program just as the way you would do your calculations by hand. Define a variable called sum and set it to zero. Decide on the number of sub-intervals, call it ni. Calculate the values of the function (1/(1+x^2) from 0 to 1 using the appropriate multiplication factors.
 
I haven't even tried to write the program yet because I don't know anything about programming. I have yet to take a programming course.
 
I haven't even tried to write the program yet because I don't know anything about programming. I have yet to take a programming course.
In that case, two questions come to light.
1. Is Fortran 77 a language requirement prescribed by someone? Why not C, C++, VB.net, Perl, C# or Java?
2. If it is the answer/result that is essential, could you try using Excel, which will give you an answer without programming at all?
 

Similar threads

Back
Top