Find Area Under Curve w/ Fortran Riemann Sums

In summary, the conversation is about using Riemann's sums to find the area under a curve for a given function, with a specified tolerance for the difference between successive iterations. The individual is unsure of how to set it up and is seeking help from others. They have a program set up to calculate the Riemann sum but need help with the outside loop to calculate the negligible error and exit the program.
  • #1
tactical
6
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
  • #2
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.
 
  • #3
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:

Related to Find Area Under Curve w/ Fortran Riemann Sums

1. What is the purpose of finding the area under a curve using Fortran Riemann Sums?

The purpose of finding the area under a curve using Fortran Riemann Sums is to calculate the approximate area between a curve and the x-axis. This is useful in many scientific and mathematical applications, such as calculating the volume of irregularly shaped objects or finding the probability of an event occurring.

2. How does Fortran Riemann Sums work?

Fortran Riemann Sums works by dividing the area under a curve into smaller, equally-sized rectangles. The height of each rectangle is determined by the value of the curve at a specific x-coordinate, and the width is determined by the distance between two consecutive x-coordinates. The sum of the areas of these rectangles gives an approximation of the total area under the curve.

3. What are the advantages of using Fortran Riemann Sums over other methods?

One advantage of using Fortran Riemann Sums is its simplicity and efficiency in calculating the area under a curve. It also allows for a more accurate approximation of the area compared to other methods, such as the trapezoidal rule or Simpson's rule.

4. What are the limitations of Fortran Riemann Sums?

A major limitation of Fortran Riemann Sums is that it can only approximate the area under a curve, and the accuracy depends on the number of rectangles used. It also assumes that the curve is continuous, which may not always be the case in real-world applications.

5. How can I implement Fortran Riemann Sums in my scientific research?

Fortran Riemann Sums can be implemented in your scientific research by using a programming language that supports the Fortran syntax, such as Fortran 90 or Fortran 95. You can also use pre-existing Fortran libraries or code snippets for calculating the area under a curve using Riemann Sums. It is important to understand the mathematical concepts behind Riemann Sums and to choose an appropriate number of rectangles for a desired level of accuracy.

Similar threads

  • Programming and Computer Science
Replies
20
Views
3K
  • Programming and Computer Science
Replies
4
Views
7K
  • Calculus and Beyond Homework Help
Replies
14
Views
352
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
11
Views
9K
  • Programming and Computer Science
Replies
20
Views
1K
Back
Top