Mathematica: Integrating over data sets?

In summary, you have a set of data, xi(ρ), which you want to integrate over a distribution function (log-normal in this case). You have a functional form for ρ f(ρ), but only have values for x(ρ) at discrete values of ρ. You need to interpolate x(ρ) for some large range of ρ, but this is a separate question that you've posted separately.
  • #1
ramparts
45
0
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?
 
Physics news on Phys.org
  • #2
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
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
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
CompuChip said:
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

1. What is Mathematica and how is it used for integrating over data sets?

Mathematica is a powerful computer program used for mathematical, statistical, and scientific calculations. It can also be used for data analysis, including integrating over data sets. This means that Mathematica can perform numerical integration on a set of data points to find the area under a curve or the volume under a surface.

2. Can Mathematica integrate over non-numerical data sets?

Yes, Mathematica has built-in functions that can handle non-numerical data sets, such as strings or symbols. These functions use various algorithms to transform the data into a form that can be integrated over.

3. How does Mathematica handle missing or invalid data points during integration?

Mathematica has robust error-handling capabilities, so it can handle missing or invalid data points during integration. It will either skip over these points or use interpolation to estimate their values.

4. Are there any limitations to the size or complexity of data sets that Mathematica can integrate over?

Mathematica can handle data sets of any size, from small to very large. However, the time it takes to integrate over a data set may increase with its size and complexity.

5. Can Mathematica integrate over data sets from external sources?

Yes, Mathematica has functions that allow for importing data sets from external sources, such as spreadsheets or databases. These data sets can then be easily integrated over within Mathematica.

Similar threads

Replies
3
Views
484
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
246
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
211
Back
Top