Calculating pi using Riemann Sum and Fortran77

In summary: No, it is not a language requirement.2. No, it is not possible to do the calculation without programming.
  • #1
ncp1044
8
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
  • #2
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.
 
  • #3
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.
 
  • #4
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.
 
  • #5
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.
 
  • #6
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?
 

FAQ: Calculating pi using Riemann Sum and Fortran77

1. What is a Riemann Sum in Fortran77?

A Riemann Sum in Fortran77 is a mathematical method used to approximate the area under a curve by dividing the curve into smaller rectangles and summing up their areas. This is done using the Fortran77 programming language, which was popular in the late 1970s and used for scientific computing.

2. How is a Riemann Sum calculated in Fortran77?

In Fortran77, a Riemann Sum is calculated by using a loop to divide the curve into smaller rectangles, calculating the area of each rectangle, and then adding up all the areas to approximate the total area under the curve.

3. What are the advantages of using Fortran77 for Riemann Sums?

Fortran77 is a powerful and efficient programming language, making it well-suited for complex mathematical calculations like Riemann Sums. It also has built-in functions for numerical integration, making it easier to implement the Riemann Sum method.

4. Are there any limitations to using Fortran77 for Riemann Sums?

One limitation of using Fortran77 for Riemann Sums is that it can be difficult to read and understand for those not familiar with the language. It also does not have some of the advanced features and capabilities of newer programming languages.

5. How can I improve the accuracy of my Riemann Sums in Fortran77?

To improve the accuracy of Riemann Sums in Fortran77, you can increase the number of rectangles used to approximate the curve, or use a more sophisticated method such as the Trapezoidal Rule or Simpson's Rule. You can also check for errors in your code and make sure that your step size (the width of each rectangle) is small enough to accurately represent the curve.

Similar threads

Replies
6
Views
1K
Replies
15
Views
3K
Replies
2
Views
6K
Replies
14
Views
968
Replies
16
Views
3K
Replies
11
Views
1K
Replies
3
Views
2K
Back
Top