Efficient table lookup

1 view (last 30 days)
Chad Greene
Chad Greene on 24 May 2012
I have a simple question, but related answers in this forum are confusing to me and seem overly complex. Thermodynamic properties of gases such as enthalpy h and entropy s are often given in tables grouped by pressure, then sorted by temperature. For example, a table might look like this:
P (kPa) T (K) h (J) s (J/K)
100 200 -50.0 -0.202
100 210 -55.3 -0.198
100 220 -60.2 -0.188
200 200 -100.1 -0.717
200 210 -95.2 -0.683
200 220 -92.4 -0.659
I have imported a much larger version of the table above and I have defined a vector for each column. The vectors are called P, T, h, and s. What's the simplest, most computationally-efficient method of linearly interpolating h and s for a given P and T?

Answers (2)

Sean de Wolski
Sean de Wolski on 24 May 2012
One of these:
doc interp1
doc interp2
Are h,s dependent on both P,T? If so, interp2(), else if each is dependent only on one, interp1()
  5 Comments
Sean de Wolski
Sean de Wolski on 25 May 2012
in you above case you would define a grid as:
[xx yy] = meshgrid([100 200],[200 210 220]);
This would be the grid corresponding to your data. You would need to reshape h, s so that they are 2x3 (or 3x2)matrices with each point being the corresponding point from P,T. Then you need to make a new grid you wish to interpolate to, for example:
[xxi yyi] = meshgrid(100:10:200,200:1:220);
And then interp2 with the above, twice, once for h and once for s.
hi = interp2(the_other_stuff, h)
si = interp2(the_other_stuff,s)
Vi will
Chad Greene
Chad Greene on 25 May 2012
Ah, reshaping was the ticket. I followed the wage example in the interp2 help file, and in doing so avoided the need for any meshing.

Sign in to comment.


Honglei Chen
Honglei Chen on 24 May 2012
On top of Sean's answer. In case your grid is not uniform (although it seems that they are based on your description), you can use griddedInterpolant and TriScatteredInterp
doc griddedInterpolant
doc TriScatteredInterp
  2 Comments
Chad Greene
Chad Greene on 24 May 2012
Hmm... I don't have griddedInterpolant. Regarding TriScatteredInterp, I've found that it's awfully slow considering the algebraic calculation of a simple linear 2D interpolation could be done by hand. I am not volunteering to actually do these calculations by hand, but the slowness of TriScatteredInterp makes me think it's doing a lot more work than it needs to do.
Sean de Wolski
Sean de Wolski on 25 May 2012
Your data appears to be on regular grid and thus you are correct. The triangulated interpolatants are overkill.

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!