I need discover a value using Linear Interpolation.

7 views (last 30 days)
I need discover a value using Linear Interpolation. For example I need a value corresponding a 3000 psia and 150 °F.
My Matrix:
McKetta(1,:)=[0 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 200 240 280];
McKetta(2,:)=[15 3 10 27 70 170 380 750 1550 3000 5500 9500 17000 28000 46000 90000 200000];
McKetta(3,:)=[25 2 6 16 45 100 220 480 900 1750 3100 5800 9500 15000 27000 50000 110000];
McKetta(4,:)=[50 1 3 9 24 58 120 250 450 850 1500 2700 4700 7200 13000 23000 50000];
McKetta(5,:)=[100 0 2 5 13 30 63 130 240 480 750 1400 2200 3800 6600 12000 24000];
McKetta(6,:)=[200 0 1 3 7 16 35 70 130 250 400 700 1200 1900 3000 6000 12000];
McKetta(7,:)=[300 0 0 2 5 11 24 47 90 170 290 480 800 1300 2000 4000 8500];
McKetta(8,:)=[400 0 0 2 4 9 20 37 70 135 220 370 600 1000 1500 3000 6200];
McKetta(9,:)=[500 0 0 1 3 7 16 30 60 105 180 300 500 840 1200 2600 5000];
McKetta(10,:)=[600 0 0 1 3 7 14 26 50 90 160 250 450 700 1000 2100 4200];
McKetta(11,:)=[800 0 0 0 2 5 11 20 40 75 130 200 350 550 800 1700 3300];
McKetta(12,:)=[1000 0 0 0 2 5 10 18 34 60 105 180 300 470 690 1400 2800];
McKetta(13,:)=[1500 0 0 0 2 3 7 14 25 46 80 130 220 340 500 1000 2000];
McKetta(14,:)=[2000 0 0 0 1 3 6 12 21 38 67 110 180 260 400 800 1600];
McKetta(15,:)=[3000 0 0 0 0 0 0 0 18 30 52 85 130 200 300 600 1150];
McKetta(16,:)=[4000 0 0 0 0 0 0 0 16 26 45 75 110 180 255 500 950];
McKetta(17,:)=[5000 0 0 0 0 0 0 0 15 24 40 69 100 160 230 450 800];
McKetta(18,:)=[6000 0 0 0 0 0 0 0 14 22 37 61 95 150 200 400 750];
McKetta(19,:)=[8000 0 0 0 0 0 0 0 13 21 34 55 85 130 180 350 650];
McKetta(20,:)=[10000 0 0 0 0 0 0 0 12 20 32 50 79 125 170 340 600];
y=table2(McKetta,3000,150)
results:
Undefined function 'table2' for input arguments of type 'double'.
:-(

Answers (2)

Joseph Cheng
Joseph Cheng on 7 Oct 2015
look up the function interp2. using the example you should get something like
temp=McKetta(1,2:end);
psi = McKetta(2:end,1)';
[tempGrid psigrid] = meshgrid(temp,psi)
McKetta(:,1)=[];
McKetta(1,:)=[];
interp2(tempGrid,psigrid,McKetta,150,3000)

Star Strider
Star Strider on 7 Oct 2015
This seems to work:
PSI = McKetta(2:end,1);
TF = McKetta(1,2:end);
[PSIM,TFM] = meshgrid(TF,PSI);
PSITF = McKetta(2:end, 2:end);
Result = interp2(PSIM,TFM,PSITF, 150, 3000)
Result =
107.5000
  2 Comments
Star Strider
Star Strider on 7 Oct 2015
My pleasure. Your English is fine.
Your ‘McKetta’ matrix is a matrix of values, the first column being the PSI values, and the first row being the Temperature. (The rest of it are your data of interest.) The interp2 function uses ‘gridded’ values to do its interpolations (it has to have specific values for both Temperature and PSI for each of the data values), so it is necessary to create those grids using the ‘PSI’ and TF vectors with the meshgrid function. The actual data in your matrix are in the ‘PSITF’ matrix (eliminating the first row and first column from your original matrix).
The ‘Result’ value is the output of the 2D linear interpolation done by the interp2 function. It takes the original data (the grids of the independent variables ‘PSIM’ and ‘TFM’) that it uses to refer to the values of your matching data matrix (here ‘PSITF’), and interpolates to find the value of the matrix that corresponds to the Temperature and PSI values (in that order) you want.
Experiment with different values and column vectors for different values to see how the interp2 function works.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!