Efficient table lookup

조회 수: 2 (최근 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