Fortran Find Area Under Curve w/ Fortran Riemann Sums

AI Thread Summary
The 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 is unsure about how to set up the loops and compute the area accurately, specifically how to implement the condition for successive iterations to yield a change of less than 0.0000001. Suggestions include using the function values at the left, right, or midpoint of subintervals to calculate the area for each segment. Additionally, a method for tracking the change in area between iterations is discussed, emphasizing the need for an outer loop to monitor convergence. Overall, the conversation aims to clarify the implementation of Riemann sums in Fortran for precise area calculation.
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:
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
20
Views
4K
Replies
21
Views
3K
Replies
1
Views
3K
Replies
6
Views
3K
Replies
14
Views
2K
Replies
5
Views
13K
Replies
20
Views
2K
Replies
3
Views
3K
Back
Top