Mathematica: Integrating over data sets?

Click For Summary

Discussion Overview

The discussion revolves around integrating a function over a distribution using Mathematica, specifically focusing on a set of discrete data points and a log-normal distribution function. Participants explore methods for performing this integration accurately given the challenges of numerical computation and the nature of the data.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks guidance on integrating a function defined by discrete data points over a log-normal distribution, expressing concern about the accuracy of simple summation methods.
  • Another participant questions the definition of xi(ρ) and clarifies that the integration should be performed using discrete values of x(ρi) instead.
  • A suggestion is made to use an InterpolatingFunction in Mathematica to create a continuous representation of the discrete data for integration purposes.
  • The original poster acknowledges the suggestion and expresses intent to try the proposed method for integration.
  • A later post indicates the original poster encountered another question related to the integration process, which they have chosen to post separately.

Areas of Agreement / Disagreement

Participants generally agree on the approach of using interpolation for the integration, but there is no consensus on the best method to handle the integration given the complexities of the data and function involved.

Contextual Notes

The discussion highlights the challenges of integrating functions defined by discrete data points and the potential limitations of numerical methods in Mathematica. Specific assumptions about the behavior of the underlying function and the distribution are not fully resolved.

ramparts
Messages
44
Reaction score
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
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
\sum_{i} x(\rho_i) \rho_i f(\rho_i) \text{?}
 
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!
 
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}]
 
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!
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K