Help with interpolating - INTERP2
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
the cyclist
le 15 Fév 2012
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.
Réponse acceptée
the cyclist
le 15 Fév 2012
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)
0 commentaires
Plus de réponses (1)
Sean de Wolski
le 15 Fév 2012
From:
doc interp2
X and Y must be monotonic
I was confused for a minute too. Use TriScatteredInterp.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!