Working with functions defined by Interpolation in Mathematica

In summary, when working with functions defined by "Interpolation" in Mathematica, if you know the value of the function and one variable, you can use a numerical method such as FindRoot or InverseFunction to determine the value of the other variable. However, the solution may not be unique.
  • #1
evgenx
14
0
Working with functions defined by "Interpolation" in Mathematica

Hello,

Just perhaps a simple question for a Mathematica expert:

I have a function of two variables f(a,b) defined using Interpolation option
in Mathematica. I am wondering how to determine the value of one of the
variable if I know the value of the other variable and the value of the function.
Many thanks!


Evgeniy
 
Physics news on Phys.org
  • #2


So you know f[x,y]==z for some y and z
Then to find x you need to use a numerical method to find when f[x, y] - z == 0.
Note that, depending on the function, this solution won't necessarily be unique.

Anyway, here's a test function:

data = Flatten[Table[{{x, y}, E^(x + y)}, {x, 4}, {y, 4}], 1]

f = Interpolation[data]

which you can visualize using

ContourPlot[f[x, y], {x, 1, 4}, {y, 1, 4}]

Then if, e.g., y=3, z=140, what does x = ?

In[]:= FindRoot[f[x, 3] == 140, {x, 2.5}]
Out[]= {x -> 1.93157}

Check:
In[]:= Exp[4.93157]
Out[]= 138.597

It's not exactly right, but pretty good considering how few points were used for the interpolation.

In general you can construct a function that gives the solution using InverseFunction:

In[26]:= Solve[g[x, y] == z, x]
Out[26]= {{x -> InverseFunction[g, 1, 2][z, y]}}

So

In[28]:= InverseFunction[f, 1, 2][140, 3] // N
Out[28]= 1.93157

which matches the FindRoot approach (and probably uses the same or similar algorithm internally).
 

1. What is interpolation in Mathematica?

Interpolation in Mathematica is a method of constructing new data points within the range of a known set of data points. It involves creating a function that passes through the known data points and can be used to estimate values at points in between. This is useful for visualizing and analyzing data, as well as predicting values at unknown points.

2. How do you define a function using interpolation in Mathematica?

To define a function using interpolation in Mathematica, you can use the Interpolation function. This function takes in a list of data points, along with any desired options, and returns a function that can be evaluated at any point within the range of the data. The function can then be used like any other function in Mathematica.

3. What types of interpolation methods are available in Mathematica?

Mathematica offers a variety of interpolation methods, including linear, polynomial, and spline interpolation. Linear interpolation connects data points with straight lines, while polynomial interpolation uses a polynomial function to pass through the points. Spline interpolation uses piecewise polynomial functions to create a smoother curve that passes through the points.

4. Can interpolation be used for data sets with missing values?

Yes, interpolation can be used for data sets with missing values. Mathematica has built-in functions, such as Missing and MissingDataMethod, to handle missing values in data sets. These functions can be used in conjunction with interpolation to estimate values at the missing points and create a complete function.

5. Are there any limitations to using interpolation in Mathematica?

One limitation of using interpolation in Mathematica is that it assumes a smooth and continuous relationship between data points. This may not always be the case in real-world data sets, and the resulting interpolated function may not accurately represent the data. Additionally, the choice of interpolation method and options can greatly affect the accuracy and reliability of the function. It is important to carefully consider these factors when using interpolation in Mathematica.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
412
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
261
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
896
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Programming and Computer Science
Replies
3
Views
355
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Back
Top