Efficient table lookup
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
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
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
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 个评论
Sean de Wolski
2012-5-25
Your data appears to be on regular grid and thus you are correct. The triangulated interpolatants are overkill.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!