Working with functions defined by Interpolation in Mathematica

Click For Summary
SUMMARY

This discussion focuses on using the "Interpolation" function in Mathematica to solve for one variable in a two-variable function when the other variable and the function's value are known. The user Evgeniy demonstrates how to find the value of x given y and z using numerical methods, specifically the FindRoot function. A sample dataset is provided, and the results show that the interpolation method yields a close approximation to the expected value. Additionally, the InverseFunction method is introduced as an alternative approach to achieve the same result.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of interpolation methods in numerical analysis
  • Knowledge of numerical root-finding techniques, specifically FindRoot
  • Basic concepts of function visualization using ContourPlot
NEXT STEPS
  • Explore the "FindRoot" function in Mathematica for solving equations numerically
  • Learn about "InverseFunction" in Mathematica for solving inverse problems
  • Investigate advanced interpolation techniques in Mathematica, such as "InterpolationOrder"
  • Study the use of "ContourPlot" for visualizing multi-variable functions in Mathematica
USEFUL FOR

Mathematica users, data scientists, and researchers who need to solve multi-variable equations and optimize interpolation methods for numerical analysis.

evgenx
Messages
14
Reaction score
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


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).
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K