Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Integrals

ericcf
Beginner
391 Views
hello everybody,

I'm new in Fortran and I'm trying to clear some things in my mind regarding the program since there are many times feeling like lost in space.

My problem is that I want to write a program in order to evaluate a simple (defined) integral and I don't know from where to start.

it will be very helpfull if somebody could give me a hand on this. so?
0 Kudos
3 Replies
isn-removed200637
391 Views
1) Get yourself a FORTRAN primer.
2)Understand the behaviour of the function of an independant variable that will be your integrand, by plotting it out for the range over which you want to integrate.
3) choose your method for approximation of a finite integral: e.g. Simpson's rule using the integrand evaluated at equispaced values of the independant variable
4)Once you know if the function is smooth, or once you know where it has rapid changes of gradient, you can choose the approximate size of the interval between points so that you have several points covering the region of greatest rate of change of gradient. This is to ensure some reasonable accuracy for the integration.

Then draw a flow diagram representing the stages of your computation as follows:

5)select the lower and upper limits of integration, divide the difference by this initial approximate interval, round the number up to the nearest integer to get an integer number of intervals, divide the actual range by this integer to get exact interval. Add 1 to get the number of points including both end points.
6) Initialise to zero a variable to store the running total
7)Starting at the first point, evaluate the integrand at that point, multiply it by the required weight for that point and add the product to the running total
8) continue up to the last point by adding the interval value to the previous value of the variable and evaluating the integrand and adding the weighted result to the running total, doing this for each point.
9) the final value in the running total is the approximate value of the definite integral between the limits you have selected.

10) code each stage
11) compile
12) debug
13) repeat 11 + 12 add infinitum
14) run
15) debug
16) repeat 14+15 (+ 11 + 12, you will add errors!)
17) check your answer

The 'weights' mentioned above depend on the method of approximation you choose. Simpson's Rule uses 0.5 as weights for the first and last points and 1.0 as weights for the intervening ones. HTH
0 Kudos
ericcf
Beginner
391 Views
thanx a lot for your help! i hope to make some progress soon!

Cheers!
0 Kudos
david_a_levinthal
391 Views
note: you can also use a monte carlo technique..
assume you know the maximum value your function takes over the range you are integrating..call it MAX
and you are integrating from X0 to X1 and X1-X0 = LEN
the area of the rectangle is LEN * MAX
in a loop throw a lot of pairs of random numbers x,y
if (y < function(x))sum = sum+1

at the end the area is sum/total_iteration * MAX*LEN

at least it is easy
0 Kudos
Reply