How to Compute an Integral Using FORTRAN?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
Chris Red
Messages
1
Reaction score
0
Thread moved from a technical section, so is missing the homework template
I have a question set for programming to compute integral for the following unknown function using composite rectangle method, trapezoidal rule and simpsons rule.

[tex]\int_{0}^{1.8} f(x) dx[/tex]

for h=0.3 and h=0.4

I have a table of results for f(x) and x as follows
x=0, 0.3, 0.6, 0.9, 0.12, 0.15, 0.18
f(x)=0.5, 0.6, 0.8, 1.3, 2, 3.2, 4.8

My interval is 6 using the formula n=1.8-0/0.3 for the first case. I am just wondering how I should approach this problem in my programming.

For the rectangle method does anyone have a step by step guide of how this would be done analytically. Surely this would also require the user to enter all values for f(x) too or they be read from a file in some way? I am mainly struggling because I am not sure how to implement this into my program which is in FORTRAN. I have not even thought about how to tackle the trapezoidal or simpson rule yet! Ideally they should be all within one program where the user selects the method of approximation.

Thanks for any advice
 
on Phys.org
Chris Red said:
I have a question set for programming to compute integral for the following unknown function using composite rectangle method, trapezoidal rule and simpsons rule.
I don't know the composite rectangle method. I'm familiar with using rectangles, where you use either the left endpoint of each subinterval or the right endpoint.
Chris Red said:
[tex]\int_{0}^{1.8} f(x) dx[/tex]

for h=0.3 and h=0.4

I have a table of results for f(x) and x as follows
x=0, 0.3, 0.6, 0.9, 0.12, 0.15, 0.18
f(x)=0.5, 0.6, 0.8, 1.3, 2, 3.2, 4.8
Are you also given a table of results for h = 0.4? Also, a stepsize of 0.4 is problematic, since 0.4 doesn't divide 1.8 evenly.
Chris Red said:
My interval is 6
No, the number of subintervals is 6.
Chris Red said:
using the formula n=1.8-0/0.3 for the first case. I am just wondering how I should approach this problem in my programming.
The right side of your formula should be written as (1.8 - 0)/0.3. Otherwise, due to the order of operations, what you wrote is 1.8 - (0/0.3) = 1.8.
Chris Red said:
For the rectangle method does anyone have a step by step guide of how this would be done analytically.
?
Are you asking how you should do the calculations? The term analytically implies the opposite of integrating numerically; i.e., by finding the antiderivative of your function and evaluating it at the two endpoints.
Chris Red said:
Surely this would also require the user to enter all values for f(x) too or they be read from a file in some way? I am mainly struggling because I am not sure how to implement this into my program which is in FORTRAN. I have not even thought about how to tackle the trapezoidal or simpson rule yet! Ideally they should be all within one program where the user selects the method of approximation.

Thanks for any advice
 
For ##h = 0.3##.

You should numerically estimate the integral using the composite trapezoidal rule. This will give you a good idea of the the correct answer at first.

Then, you should notice that the step size causes there to be an even number of segments (6) and an odd number of data points (7). This tells you that a Simpson's 1/3 approach would be most appropriate.

Write functions in FORTRAN that return the values for the respective methods (trapezoidal/Simpson's).

For ##h = 0.4##.

There is a serious problem. You can't even numerically estimate the integral with the composite trapezoidal rule using unequal step sizes for each segment. This is because the step size makes your data obsolete.

A step size of ##0.6## would prove more interesting.