Efficient table lookup

3 次查看(过去 30 天)
Chad Greene
Chad Greene 2012-5-24
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?

回答(2 个)

Sean de Wolski
Sean de Wolski 2012-5-24
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 个评论
Sean de Wolski
Sean de Wolski 2012-5-25
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 2012-5-25
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.

请先登录,再进行评论。


Honglei Chen
Honglei Chen 2012-5-24
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 个评论
Chad Greene
Chad Greene 2012-5-24
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 2012-5-25
Your data appears to be on regular grid and thus you are correct. The triangulated interpolatants are overkill.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by