Mathematica: Integrating over data sets?

  • Mathematica
  • Thread starter ramparts
  • Start date
  • #1
45
0

Main Question or Discussion Point

I've got a Mathematica question which might be quite basic, but I couldn't find much about it in the documentation (possibly because it's so basic) so please bear with me!

I have a set of data, call it xi(ρ), which I want to integrate over some distribution function (log-normal in this case) given by f(ρ). In particular I want to compute the integral

∫ x(ρ) ρ f(ρ) dρ

from 0 to infinity (although since I don't have xi(ρ) from 0 to infinity I'd cut the calculation off at some upper and lower bound where f(ρ) becomes negligible).

So I have a functional form for ρ f(ρ), but only have values for x(ρ) at discrete values of ρ. How can I do this integral accurately in Mathematica?
 

Answers and Replies

  • #2
CompuChip
Science Advisor
Homework Helper
4,302
47
I think I don't completely understand the question..
What is xi(ρ)? Is it a set of functions of ρ? In that case, what is x(ρ) in the integrand, is it computed from the xi(ρ)?

Or do you mean that you have values for discrete ρ only, so that we're actually talking about x(ρi)? In that case, wouldn't you normally do something like
[tex]\sum_{i} x(\rho_i) \rho_i f(\rho_i) \text{?}[/tex]
 
  • #3
45
0
Yeah, I meant x(ρi) as you said - I was typing this post in a hurry! I could do that sum myself fairly simply in C but I figured Mathematica probably has more accurate numerical integration techniques. Since the log-normal distribution has some fairly steep gradients I'm worried I might not get the most accurate answers by doing a simple sum like that.

So the idea is there's some underlying function x(ρ) for which I want to do that integral, but the function x(ρ) is pretty complicated and has to be computed numerically by a code that I downloaded. I tell this program ρ and it gives me x, so I'm thinking of having it compute x(ρ) for some large range of ρ, importing those numbers into Mathematica and doing the integral.

Hope that makes sense!
 
  • #4
CompuChip
Science Advisor
Homework Helper
4,302
47
Yep, it makes more sense now.
So you have a large discrete set of function values, and you would like to make a continuous function that you can use in the integration, right?

In that case, maybe you should have a look at the InterpolatingFunction. I don't have Mathematica at hand, but you could try something like
Code:
points = { {rho1, x1}, {rho2, x2}, ...., {rho10000, x10000}};
x = Interpolation[points];
NIntegrate[x[rho] rho f[rho], {rho, rho1, rho10000}]
 
  • #5
45
0
Yep, it makes more sense now.
So you have a large discrete set of function values, and you would like to make a continuous function that you can use in the integration, right?

In that case, maybe you should have a look at the InterpolatingFunction. I don't have Mathematica at hand, but you could try something like
Code:
points = { {rho1, x1}, {rho2, x2}, ...., {rho10000, x10000}};
x = Interpolation[points];
NIntegrate[x[rho] rho f[rho], {rho, rho1, rho10000}]
Thanks, this looks like exactly what I need, I'll try this!
 
  • #6
45
0

Related Threads on Mathematica: Integrating over data sets?

Replies
2
Views
3K
Replies
1
Views
3K
Replies
2
Views
5K
Replies
14
Views
9K
Replies
0
Views
1K
Replies
6
Views
11K
Replies
5
Views
5K
Replies
12
Views
24K
Replies
4
Views
3K
Replies
2
Views
2K
Top