Mathematica: Interpolation Functions

In summary, the conversation discussed the use of Interpolation to integrate a probability density function (PDF) from 0 to a certain value. It was suggested to split the data set into two sublists and use two separate interpolating functions to account for the "gap" in the data. Another approach was to define the function conditionally based on the different ranges of the data.
  • #1
Niles
1,866
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
  • #2
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.
 
  • #3
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.
 
  • #4
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.
 
  • #5


Hello Niles,

Thank you for sharing your question about interpolation functions in Mathematica. Interpolation functions are a powerful tool for approximating a function from a set of discrete data points. In your case, it sounds like you have a PDF with a gap and you want to find the integral of the function from 0 to a specific value.

To account for the gap in your data, you can use the option "ExtrapolationHandler" when creating your interpolation function. This allows you to specify how the function should behave outside of the given data range. In your case, you can use the option "Constant" to specify that the function should remain constant outside of the data range.

For example, you can create an interpolation function with this option as follows:

Interpolation[data, InterpolationOrder -> 1, ExtrapolationHandler -> {0 &}]

This will create an interpolation function that is 0 for all values outside of the data range.

As for your second problem, you can use the option "Domain" to specify the desired range of your interpolation function. For example, you can create an interpolation function that runs from 0 to 22 as follows:

Interpolation[data, InterpolationOrder -> 1, Domain -> {0, 22}]

I hope this helps! Let me know if you have any other questions or need further clarification. Best of luck with your research.

Sincerely,
 

FAQ: Mathematica: Interpolation Functions

What is Mathematica and what are Interpolation Functions?

Mathematica is a computational software program used for a variety of scientific and mathematical calculations. Interpolation Functions are a feature within Mathematica that allow for the approximation of a function based on a set of data points.

How do I create an Interpolation Function in Mathematica?

An Interpolation Function can be created by using the Interpolation command in Mathematica. This command takes in a set of data points and returns a function that approximates the data.

Can I use Interpolation Functions for data that is not evenly spaced?

Yes, Interpolation Functions in Mathematica can handle non-uniformly spaced data points. It uses a mathematical algorithm to interpolate the data and create a smooth function.

Are there different types of Interpolation Functions in Mathematica?

Yes, Mathematica offers several types of Interpolation Functions, such as linear, polynomial, and spline. Each type uses a different method to approximate the data and has its own advantages and limitations.

How accurate are Interpolation Functions in Mathematica?

The accuracy of an Interpolation Function in Mathematica depends on the type of data and the chosen interpolation method. Generally, Interpolation Functions provide a good approximation of the data, but it is always recommended to evaluate the function and check for any discrepancies.

Similar threads

Replies
4
Views
2K
Replies
4
Views
1K
Replies
4
Views
1K
Replies
2
Views
2K
Replies
2
Views
3K
Replies
4
Views
1K
Replies
1
Views
802
Replies
2
Views
4K
Back
Top