1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Riemann Sum with Fortran77

  1. Nov 23, 2008 #1
    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?
  2. jcsd
  3. Nov 23, 2008 #2
    A priori, homework and assignment question should be posted in the appropriate section, namely:

    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.
  4. Nov 24, 2008 #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.
  5. Nov 24, 2008 #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.
  6. Nov 25, 2008 #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.
  7. Nov 25, 2008 #6
    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?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook