Mathematica: Interpolation Functions

Click For Summary

Discussion Overview

The discussion revolves around the challenges of using interpolation functions in Mathematica for a given data set representing a probability density function (PDF). Participants explore methods to handle gaps in the data and ensure the resulting function behaves appropriately as a PDF.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant presents a data set and expresses the need for an interpolating function to integrate it, noting a gap in the data where the PDF is zero.
  • Another participant confirms that Mathematica's Interpolation can accept the data format provided but questions whether the resulting function is a valid PDF due to negative values generated in the interpolation.
  • A third participant suggests splitting the data into two sublists to create two separate interpolating functions, proposing a conditional definition for the overall function to handle the gaps appropriately.
  • The original poster acknowledges the suggestions and indicates a need for further consideration of the problem.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to ensure the interpolating function remains a valid PDF. Multiple competing views and methods are presented without resolution.

Contextual Notes

Participants highlight the limitations of the interpolation method in maintaining non-negativity and the requirement for the area under the PDF to equal one, indicating unresolved mathematical considerations.

Niles
Messages
1,834
Reaction score
0
Hi

I have a data set of the form:

Code:
data = {{0, 0}, {1, 1}, {2, 2}, {3, 20}, {4, 1}, {20, 1}, {21, 1}, {22, 0}};

This data set is a probability density function (PDF), and I need to be able to integrate it from 0 to some x<22. I thought that I would use an interpolating function for this. However, there is a "gap" between 4 and 20, where the PDF is zero, but an interpolating function doesn't take that into account by itself (I think). Is there a smarter way of accounting for this other than manually inserting data points?

The second problem is that ListInterpolation only takes a 1D-list. So I can only feed it the 2nd coordinate of the data points. However, I need somehow for the interpolation function to run from 0 to 22. I don't know how to do that.

I appreciate any help and suggestions.


Niles.
 
Physics news on Phys.org
As
http://reference.wolfram.com/mathematica/ref/Interpolation.html
shows, Interpolation happily accepts a list of {x,f[x]}.

For example
In[1]:= f=Interpolation[{{0,0},{1,1},{2,2},{3,20},{4,1},{20,1},{21,1},{22,0}}]
Out[1]= InterpolatingFunction[{{0,22}},<>]

But the question becomes whether this is an adequate PDF.

In[2]:= Table[{t,f[t]},{t,0,22}]
Out[2]= {{0, 0}, {1, 1}, {2, 2}, {3, 20}, {4, 1}, {5, -709/51}, {6, -1279/51}, {7, -1678/51}, {8, -1925/51}, {9, -2039/51}, {10, -2039/51}, {11, -648/17}, {12, -591/17}, {13, -515/17}, {14, -1279/51}, {15, -994/51}, {16, -709/51}, {17, -443/51}, {18, -215/51}, {19, -44/51}, {20, 1}, {21, 1}, {22, 0}}

That clearly shows that the interpolation fits your given points exactly, but is not PDF-aware and you need to find a radically different approach to your problem to come up with something that will be non negative and with an area=1.
 
Yes, split your list into two sublists:

Code:
data1 = {{0, 0}, {1, 1}, {2, 2}, {3, 20}, {4, 1}}

and

data2 = {{20, 1}, {21, 1}, {22, 0}}

An interpolating function is given only over the range where the data set is given. That is why you introduce two interpolating functions:

Code:
inter1= Interpolation[data1]

and

Code:
inter2 = Interpolation[data2]

Then, define your function conditionally:

Code:
f[x_] := 0 \; x < 0 || (x > 4 && x < 20) || x > 22;
f[x_] := inter1[x] \; x >= 0 && x <= 4;
f[x_] := inter2[x] \; x >= 20 && x <= 22;

Now f[x] is a good function.
 
Thanks for both your suggestions, that is very kind. You are right Bill Simpson, I need some other way to do this. I'll have to think about this for some time.

Thanks for the help.Niles.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K