Find Area Under Curve w/ Fortran Riemann Sums

Click For Summary
SUMMARY

This discussion focuses on using Fortran to calculate the area under the curve for the function f(x) = -(x-3)**2 + 9 using Riemann sums. The user seeks guidance on implementing double precision and setting up loops to compute the area accurately, stopping when the change between iterations is less than 0.0000001. Key methods for calculating the area include using the left endpoint, right endpoint, or midpoint of subintervals. The conversation emphasizes the need for proper loop structures to track area changes and achieve the desired precision.

PREREQUISITES
  • Fortran programming language
  • Understanding of Riemann sums
  • Knowledge of double precision arithmetic
  • Basic loop structures in programming
NEXT STEPS
  • Implement the calculation of area using left, right, and midpoint Riemann sums in Fortran
  • Research double precision data types in Fortran for improved accuracy
  • Learn about convergence criteria in numerical methods
  • Explore optimization techniques for loop performance in Fortran
USEFUL FOR

This discussion is beneficial for students and developers working with Fortran, particularly those focusing on numerical methods and Riemann sums for area calculations.

tactical
Messages
6
Reaction score
0
Hello, for my FORTRAN class it wants me to use the method of Riemann's sums to find the area under the curve for the function f(x) = -(x-3)**2 +9, and stop when successive iterations yield a change of less than 0.0000001. I know I am going to have to used double precision. I am just confused on how to set it up. This is what I am thinking...

Im going to need a loop from 1 to count, then my deltaX will be upperbound-lowerbound/count.
Then Inside that do loop I am going to need another one that does from 1 to 6 by iterations of deltaX. Then I am going to need to compute the Area(where I am stumped). After that I am going to want to say if the area after minus the area before is greater then 0.0000001 then count=count + 1. So far this is what my do loops look like. I am just wondering if i am headed in the correct direction of not? Can anyone help me please??

DO I=1,COUNT,1
deltaX = (upperBOUND-lowerBOUND)/COUNT
DO J = 0,6,deltaX
F_X=-(J-3)**2 + 9
ENDDO
ENDDO
 
Technology news on Phys.org
You have a long way to go.

You don't have anything that actually computes the area (which you acknowledged in your post), but there are several ways this could be done, including the following three.

  1. Use the function value at the left endpoint of the subinterval.
  2. Use the function value at the right endpoint of the subinterval.
  3. Use the function value at the midpoint of the subinterval.
For each subinterval [x_i, x_i + deltaX], the area is f(x)*deltaX, where x can be the left endpoint, the right endpoint, or the midpoint. You'll want to have a loop that adds all of these areas together to get the total area. And, you'll want another loop outside of that one that keeps track of how much the area has changed between the two runs. When the difference between the two runs is smaller than the specified tolerance, you're done.
 
I also have a problem very similar to this. I have my program set up to calculate the riemann sum to whatever number of sections i want, but i need some help to write the outside loop calculating the negligible error (iterationNew-iterationOld < .0000001) and exiting. Any help would be awesome
this is what i have so far:

Program wtf
IMPLICIT NONE
REAL(kind=8)s,ans
INTEGER(kind=4) I,J,G
I=0
S=0

WRITE(*,*) 'Enter the number of sub intervals you wish to use'
READ*, J

DO
IF(I.LE.J)THEN
S=S+(-(3-(I*6.0/J))**2+9)
I=I+1

ELSE IF(I.GT.J) THEN
EXIT
ENDIF
ENDDO

ans=S*(6.0/J)

WRITE(*,*)'The reimann sum is',ans

END program
 
Last edited:

Similar threads

  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
9K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 5 ·
Replies
5
Views
13K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K