Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numerical Integration with c++ on a given mesh with fixed constant discretisation

I have the following problem:

My c++ code can compute two functions

f1(i1,i2,i3,i4)

f2(j1,j2)

for every set of {i1,i2,i3,i4} I get some value of f1 and for every set of {j1,j2} I get some value of f2.

the sets {i1,i2,i3,i4} and {j1,j2} are given on a FIXED mesh with some constant discretisation step "h".

I need to calculate, in mathematical language, an Integral F3(x1,x3)=Integral[f1(x1,x2,x3,x4)*f2(x3,x4) dx3 dx4]

The the simple summation is not good enough, since f2 has many jumps.

Is there some c++ library which can do this sort of integration? Or some algorhithm which is easy to implement (I am not really good on c++)

many thanks

like image 720
Sankp Avatar asked Jan 25 '12 19:01

Sankp


2 Answers

If you only have the values at the mesh points and no further mathematical knowledge of the form of the curves there's nothing better you can do than the trivial summation.

There's no way else than to change the mesh or use completely other methods like http://en.wikipedia.org/wiki/Monte_Carlo_integration

like image 147
Johan Lundberg Avatar answered Sep 22 '22 21:09

Johan Lundberg


You can use Simpson's rule ( http://en.wikipedia.org/wiki/Simpson%27s_rule ). But, as Johan mentioned, if f2 is steep and erratic decreasing step size h is the only solution. Another approach you might want to consider is variable h across the mesh. That is:

1. Start with a global common h
2. Divide the space into smaller subspaces
3. Calculate integral for each subspace
4. Recalculate integral for each subspace using step size h/2
5. For only subspaces where difference between integrals (h and h/2) is substantial repeat the above mentioned steps (From step 3)
like image 22
ElKamina Avatar answered Sep 26 '22 21:09

ElKamina