Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculation of integration from a data set

Status
Not open for further replies.

papain

Programmer
Apr 9, 2011
4
US
Hi,
I am looking for a program in Fortran 77/90/95 to calculate integration from a data set.
I have a data set like
x1[1] x2[1] F(x1,x2)[1]
x1[2] x2[2] F(x1,x2)[2]
..... ..... ...........
..... ..... ...........
x1[n] x2[n] F(x1,x2)[n]
I need a numerical integration of the relation
F(x1) = ln ?e?F(x1,x2)dx2
so i can get array like
x1[1] F(x1)[1]
x1[2] F(x1)[2]
..... .....
..... .....
x1[n] F(x1)[n]
here is a simple Fortran program which can read the data file

dimension x1(3000,3000),x2(3000,3000),x1x2(3000,3000)
real*8 x1,x2,x1x2,sum1,dx2
integer i,j
do i=1,100
do j=1,100
read(10,*)x1(i,j),y1(i,j),x1y1(i,j)
enddo
enddo
stop
end
 
Don't understand why your x1 and x2 are 2D arrays, IMHO it should be only 1D arrays.
Here is a simple example how to read data of the function of 2 variables
However if you have other input file layout, then you have to modify the example given in the thread above.

When you have the data stored in the arrays you can compute the numerical quadrature using a rectangle or trapez rule.
 
Hi mikrom
Thanks to you.
I need a fortran program which can numerically integrate from the data set
of 2 variables using the equation like F(x1) = ln ?e?F(x1,x2)dx2 .

Please help me.
 
I don't understand what you mean with
the equation like F(x1) = ln ?e?F(x1,x2)dx2
The F in F(x1,x2) which should be a function of 2 variables cannot be the same as F in F(x1) which is the function of 1 variable.

I understand it so:
For every given x, find the Phi(x) given as
Phi(x) = ln ?e?F(x,y)dy
If I'm rigt I would do it so:
1. As I wrote above, first you have to store the tabelled values into arrays
x[1],..,x[m]
y[1],..,y[n]
F(1,1),..,F(m,n)

2. Then for every array element x[j], 1 <= j <= m compute the marginal integral ?e?F(x[j],y)dy using a formula for numerical quadrature (e.g. Trapez, Simpson,...), make the natural logarithmus of it and store the result into an array element phi[j].

3. Now you have the resulting array phi[1],..,phi[m] and you will be able to compute phi(x) for every given x (x[1] <= x <= x[m]) using numerical interpolation.
 
Hi mikrom,
Thanks a lot. you are absolutely right.
can you look into my integral program. is it like

do i=1,m
sum=0. !phi(x)
do j=1,n
dy=0.01 !intervals of width, as the interval are very small
sum=sum+exp(-F(i,j)*dy)
enddo
write(*,*)x(i),log(sum)
enddo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top