Help with interpolating - INTERP2

3 ビュー (過去 30 日間)
Reidar
Reidar 2012 年 2 月 15 日
編集済み: Cedric 2013 年 10 月 13 日
Hi, I have a table with density values dependent on pressure and temperature, rho(p,T), and I want to be able to interpolate between them. I've tried using interp2, but I keep getting errors. This is an example (lot of numbers, but the code is easy):
p = [8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6;
10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6];
T = [280.000 300.000 305.000 310.000 315.000 320.000 325.000 330.000 350.000;
280.000 300.000 305.000 310.0000 315.000 320.000 325.000 330.000 350.000];
rho = [922.92 753.17 656.77 327.71 261.29 231.91 212.90 198.87 164.16;
938.22 801.62 751.67 685.77 586.02 448.28 358.04 310.25 228.80];
density = interp2(p, T, rho, 8*10^6, 280.00)
I keep getting the error: "X and Y must be matrices produced by MESHGRID. Use TriScatteredInterp instead of INTERP2 for scattered data." But if I try using TriScatteredInterp I get the error "Input data point locations have invalid dimension." I'm not able to understand what the problem really is. Can someone help me?
  1 件のコメント
the cyclist
the cyclist 2012 年 2 月 15 日
Just as a side comment, I believe it is more accurate (and faster) to use the notation 8e6 rather than 8*10^6, which involves calculation.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2012 年 2 月 15 日
Does this give what you expect?
density = interp2(p', T', rho', 8*10^6, 280.00)
Notice that I just transposed your inputs.
Or you could try TriScatteredInterp(), as suggested. In your case, the proper syntax is
F = TriScatteredInterp(p(:),T(:),rho(:));
density = F(8e6,280)
All in all, I think I would perform this calculation as:
p = [8e6 1e7];
T = [280 300 305 310 315 320 325 330 350];
[pp,TT] = meshgrid(p,T);
rho = [922.92 753.17 656.77 327.71 261.29 231.91 212.90 198.87 164.16;
938.22 801.62 751.67 685.77 586.02 448.28 358.04 310.25 228.80]';
density = interp2(pp,TT,rho,8e6,280.00)

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 2 月 15 日
From:
doc interp2
X and Y must be monotonic
I was confused for a minute too. Use TriScatteredInterp.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by