Interpolation From A Table
2 ビュー (過去 30 日間)
古いコメントを表示
Here are the code. But the value after i input the data to use the interpolation the value is wrong. Could anyone help me figure this out ?
clear
clc
Table = [0.04 28.96 1.0040 34.800 121.45 2415.2 121.46 2432.9 2554.4 0.4226 8.4746 0.04;
0.06 36.16 1.0064 23.739 151.53 2425.0 151.53 2415.9 2567.4 0.5210 8.3304 0.06;
0.08 41.51 1.0084 18.103 173.87 2432.2 173.88 2403.1 2577.0 0.5926 8.2287 0.08;
0.10 45.81 1.0102 14.674 191.82 2437.9 191.83 2392.8 2584.7 0.6493 8.1502 0.10;
0.20 60.06 1.0172 7.649 251.38 2456.7 251.40 2358.3 2609.7 0.8320 7.9085 0.20;
0.30 69.10 1.0223 5.229 289.20 2468.4 289.23 2336.1 2625.3 0.9439 7.7686 0.30;
0.40 75.87 1.0265 3.993 317.53 2477.0 317.58 2319.2 2636.8 1.0259 7.6700 0.40;
0.50 81.33 1.0300 3.240 340.44 2483.9 340.49 2305.4 2645.9 1.0910 7.5939 0.50;
0.60 85.94 1.0331 2.732 359.79 2489.6 359.86 2293.6 2653.5 1.1453 7.5320 0.60;
0.70 89.95 1.0360 2.365 376.63 2494.5 376.70 2283.3 2660.0 1.1919 7.4797 0.70;
0.80 93.50 1.0380 2.087 391.58 2498.8 391.66 2274.1 2665.8 1.2329 7.4346 0.80;
0.90 96.71 1.0410 1.869 405.06 2502.6 405.15 2265.7 2670.9 1.2695 7.3949 0.90;
1.00 99.63 1.0432 1.694 417.36 2506.1 417.46 2258.0 2675.5 1.3026 7.3594 1.00;
1.50 111.4 1.0528 1.159 466.94 2519.7 467.11 2226.5 2693.6 1.4336 7.2233 1.50;
2.00 120.2 1.0605 0.8857 504.49 2529.5 504.70 2201.9 2706.7 1.5301 7.1271 2.00;
2.50 127.4 1.0672 0.7187 535.10 2537.2 535.37 2181.5 2716.9 1.6072 7.0527 2.50;
3.00 133.6 1.0732 0.6058 561.15 2543.6 561.47 2163.8 2725.3 1.6718 6.9919 3.00;
3.50 138.9 1.0786 0.5243 583.95 2546.9 584.33 2148.1 2732.4 1.7275 6.9405 3.50;
4.00 143.6 1.0836 0.4625 604.31 2553.6 604.74 2133.8 2738.6 1.7766 6.8959 4.00;
4.50 147.9 1.0882 0.4140 622.25 2557.6 623.25 2120.7 2743.9 1.8207 6.8565 4.50;
5.00 151.9 1.0926 0.3749 639.68 2561.2 640.23 2108.5 2748.7 1.8607 6.8212 5.00;
6.00 158.9 1.1006 0.3157 669.90 2567.4 670.56 2086.3 2756.8 1.9312 6.7600 6.00;
7.00 165.0 1.1080 0.2729 696.44 2572.5 697.22 2066.3 2763.5 1.9922 6.7080 7.00;
8.00 170.4 1.1148 0.2404 720.22 2576.8 721.11 2048.0 2769.1 2.0462 6.6628 8.00;
9.00 175.4 1.1212 0.2150 741.83 2580.5 742.83 2031.1 2773.9 2.0946 6.6226 9.00;
10.0 179.9 1.1273 0.1944 761.68 2583.6 762.81 2015.3 2778.1 2.1387 6.5863 10.0;
15.0 198.3 1.1539 0.1318 843.16 2594.5 844.84 1947.3 2792.2 2.3150 6.4448 15.0;
20.0 212.4 1.1767 0.09963 906.44 2600.3 908.79 1890.7 2799.5 2.4474 6.3409 20.0;
25.0 224.0 1.1973 0.07998 959.11 2603.1 962.11 1841.0 2803.1 2.5547 6.2575 25.0;
30.0 233.9 1.2165 0.06668 1004.8 2604.1 1008.4 1795.7 2804.2 2.6457 6.1869 30.0;
35.0 242.6 1.2347 0.05707 1045.4 2603.7 1049.8 1753.7 2803.4 2.7253 6.1253 35.0;
40.0 250.4 1.2522 0.04978 1082.3 2602.3 1087.3 1714.1 2801.4 2.7964 6.0701 40.0;
45.0 257.5 1.2692 0.04406 1116.2 2600.1 1121.9 1676.4 2798.3 2.8610 6.0199 45.0;
50.0 264.0 1.2859 0.03944 1147.8 2597.1 1154.2 1640.1 2794.3 2.9202 5.9734 50.0;
60.0 275.6 1.3187 0.03244 1205.4 2589.7 1213.4 1571.0 2784.3 3.0267 5.8892 60.0;
70.0 285.9 1.3513 0.02737 1257.6 2580.5 1267.0 1505.1 2772.1 3.1211 5.8133 70.0;
80.0 295.1 1.3842 0.02352 1305.6 2569.8 1316.6 1441.3 2758.0 3.2068 5.7432 80.0;
90.0 303.4 1.4178 0.02048 1350.5 2557.8 1363.3 1378.9 2742.1 3.2858 5.6772 90.0;
100. 311.1 1.4524 0.01803 1393.0 2544.4 1407.6 1317.1 2724.7 3.3596 5.6141 100;
110. 318.2 1.4886 0.01599 1433.7 2529.8 1450.1 1255.5 2705.6 3.4295 5.5527 110;
120. 324.8 1.5267 0.01426 1473.0 2513.7 1491.3 1193.6 2684.9 3.4962 5.4924 120.;
130. 330.9 1.5671 0.01278 1511.1 2496.1 1531.5 1130.7 2662.2 3.5606 5.4323 130.;
140. 336.8 1.6107 0.01149 1548.6 2476.8 1571.1 1066.5 2637.6 3.6232 5.3717 140.;
150. 342.2 1.6581 0.01034 1585.6 2455.5 1610.5 1000.0 2610.5 3.6848 5.3098 150.;
160. 347.4 1.7107 0.009306 1622.7 2431.7 1650.1 930.6 2580.6 3.7461 5.2455 160.;
170. 352.4 1.7702 0.008364 1660.2 2405.0 1690.3 856.9 2547.2 3.8079 5.1777 170.;
180. 357.1 1.8397 0.007489 1698.9 2374.3 1732.0 777.1 2509.1 3.8715 5.1044 180.;
190. 361.5 1.9243 0.006657 1739.9 2338.1 1776.5 688.0 2464.5 3.9388 5.0228 190.;
200. 365.8 2.036 0.005834 1785.6 2293.0 1826.3 583.4 2409.7 4.0139 4.9269 200.;
220.9 374.1 3.155 0.003155 2029.6 2029.6 2099.3 0 2099.3 4.4298 4.4298 220.9];
Table(:,12) = [];
Table(:,8) = [];
%Choose Menu
disp('This Program will retrieve the data based on your input value')
disp('Choose input data type: ')
disp('1. Pressure');
disp('2. Temperature');
disp('3. Specific Volume Sat. Liquid');
disp('4. Specific Volume Sat. Vapor');
disp('5. Internal Energy Sat. Liquid');
disp('6. Internal Energy Sat. Vapor');
disp('7. Enthalpy Sat. Liquid');
disp('8. Enthalpy Sat. Vapor');
disp('9. Entropy Sat. Liquid');
disp('10. Entropy Sat. Vapor');
choice = input('Choose from 1 to 10: ');
value = input('Please input value: ');
%Calculation
[r,c] = size(Table);
aval = 0;
for i = 1:r
if value < Table(i,choice)
aval = 2;
elseif value > Table(i,choice)
aval = 3;
elseif value == Table(i,choice)
aval = 1;
row = i;
break
end
end
if aval == 1
properties = Table(row,:);
elseif aval == 2
for i = 1:10
row = 1;
properties(1,i) = Table(row,i)+(Table(row+1,i)-Table(row,i))/(Table(row+1,choice)-Table(row,choice))*(value-Table(row,choice));
end
elseif aval == 3
for i = 1:10
row = r-1;
properties(1,i) = Table(row,i)+(Table(row+1,i)-Table(row,i))/(Table(row+1,choice)-Table(row,choice))*(value-Table(row,choice));
end
else
for i = 1:r-1
if (Table(i,choice)-value)*(Table(i+1,choice)-value) < 0
row = i;
for i = 1:10
properties(1,i) = Table(row,i)+(Table(row+1,i)-Table(row,i))/(Table(row+1,choice)-Table(row,choice))*(value-Table(row,choice));
end
break
end
end
end
%Printing
fprintf('\nProperties:\n')
fprintf('1. Pressure = %.10f bar\n', properties(1));
fprintf('2. Temperature = %.10f C\n', properties(2));
fprintf('3. Specific Volume Sat. Liquid = %.10f x 10^-3 m^3/kg\n', properties(3));
fprintf('4. Specific Volume Sat. Vapor = %.10f m^3/kg\n', properties(4));
fprintf('5. Internal Energy Sat. Liquid = %.10f kJ/kg\n', properties(5));
fprintf('6. Internal Energy Sat. Vapor = %.10f kJ/kg\n', properties(6));
fprintf('7. Enthalpy Sat. Liquid = %.10f kJ/kg\n', properties(7));
fprintf('8. Enthalpy Sat. Vapor = %.10f kJ/kg\n', properties(8));
fprintf('9. Entropy Sat. Liquid = %.10f kJ/kgK\n', properties(9));
fprintf('10. Entropy Sat. Vapor = %.10f kJ/kgK\n', properties(10));
2 件のコメント
Walter Roberson
2021 年 7 月 13 日
What are some sample inputs, and what is the expected output, and what output are you seeing instead?
採用された回答
Chunru
2021 年 7 月 13 日
You can use interp to do the task, which produce the value you want:
clear
clc
Table = [0.04 28.96 1.0040 34.800 121.45 2415.2 121.46 2432.9 2554.4 0.4226 8.4746 0.04;
0.06 36.16 1.0064 23.739 151.53 2425.0 151.53 2415.9 2567.4 0.5210 8.3304 0.06;
0.08 41.51 1.0084 18.103 173.87 2432.2 173.88 2403.1 2577.0 0.5926 8.2287 0.08;
0.10 45.81 1.0102 14.674 191.82 2437.9 191.83 2392.8 2584.7 0.6493 8.1502 0.10;
0.20 60.06 1.0172 7.649 251.38 2456.7 251.40 2358.3 2609.7 0.8320 7.9085 0.20;
0.30 69.10 1.0223 5.229 289.20 2468.4 289.23 2336.1 2625.3 0.9439 7.7686 0.30;
0.40 75.87 1.0265 3.993 317.53 2477.0 317.58 2319.2 2636.8 1.0259 7.6700 0.40;
0.50 81.33 1.0300 3.240 340.44 2483.9 340.49 2305.4 2645.9 1.0910 7.5939 0.50;
0.60 85.94 1.0331 2.732 359.79 2489.6 359.86 2293.6 2653.5 1.1453 7.5320 0.60;
0.70 89.95 1.0360 2.365 376.63 2494.5 376.70 2283.3 2660.0 1.1919 7.4797 0.70;
0.80 93.50 1.0380 2.087 391.58 2498.8 391.66 2274.1 2665.8 1.2329 7.4346 0.80;
0.90 96.71 1.0410 1.869 405.06 2502.6 405.15 2265.7 2670.9 1.2695 7.3949 0.90;
1.00 99.63 1.0432 1.694 417.36 2506.1 417.46 2258.0 2675.5 1.3026 7.3594 1.00;
1.50 111.4 1.0528 1.159 466.94 2519.7 467.11 2226.5 2693.6 1.4336 7.2233 1.50;
2.00 120.2 1.0605 0.8857 504.49 2529.5 504.70 2201.9 2706.7 1.5301 7.1271 2.00;
2.50 127.4 1.0672 0.7187 535.10 2537.2 535.37 2181.5 2716.9 1.6072 7.0527 2.50;
3.00 133.6 1.0732 0.6058 561.15 2543.6 561.47 2163.8 2725.3 1.6718 6.9919 3.00;
3.50 138.9 1.0786 0.5243 583.95 2546.9 584.33 2148.1 2732.4 1.7275 6.9405 3.50;
4.00 143.6 1.0836 0.4625 604.31 2553.6 604.74 2133.8 2738.6 1.7766 6.8959 4.00;
4.50 147.9 1.0882 0.4140 622.25 2557.6 623.25 2120.7 2743.9 1.8207 6.8565 4.50;
5.00 151.9 1.0926 0.3749 639.68 2561.2 640.23 2108.5 2748.7 1.8607 6.8212 5.00;
6.00 158.9 1.1006 0.3157 669.90 2567.4 670.56 2086.3 2756.8 1.9312 6.7600 6.00;
7.00 165.0 1.1080 0.2729 696.44 2572.5 697.22 2066.3 2763.5 1.9922 6.7080 7.00;
8.00 170.4 1.1148 0.2404 720.22 2576.8 721.11 2048.0 2769.1 2.0462 6.6628 8.00;
9.00 175.4 1.1212 0.2150 741.83 2580.5 742.83 2031.1 2773.9 2.0946 6.6226 9.00;
10.0 179.9 1.1273 0.1944 761.68 2583.6 762.81 2015.3 2778.1 2.1387 6.5863 10.0;
15.0 198.3 1.1539 0.1318 843.16 2594.5 844.84 1947.3 2792.2 2.3150 6.4448 15.0;
20.0 212.4 1.1767 0.09963 906.44 2600.3 908.79 1890.7 2799.5 2.4474 6.3409 20.0;
25.0 224.0 1.1973 0.07998 959.11 2603.1 962.11 1841.0 2803.1 2.5547 6.2575 25.0;
30.0 233.9 1.2165 0.06668 1004.8 2604.1 1008.4 1795.7 2804.2 2.6457 6.1869 30.0;
35.0 242.6 1.2347 0.05707 1045.4 2603.7 1049.8 1753.7 2803.4 2.7253 6.1253 35.0;
40.0 250.4 1.2522 0.04978 1082.3 2602.3 1087.3 1714.1 2801.4 2.7964 6.0701 40.0;
45.0 257.5 1.2692 0.04406 1116.2 2600.1 1121.9 1676.4 2798.3 2.8610 6.0199 45.0;
50.0 264.0 1.2859 0.03944 1147.8 2597.1 1154.2 1640.1 2794.3 2.9202 5.9734 50.0;
60.0 275.6 1.3187 0.03244 1205.4 2589.7 1213.4 1571.0 2784.3 3.0267 5.8892 60.0;
70.0 285.9 1.3513 0.02737 1257.6 2580.5 1267.0 1505.1 2772.1 3.1211 5.8133 70.0;
80.0 295.1 1.3842 0.02352 1305.6 2569.8 1316.6 1441.3 2758.0 3.2068 5.7432 80.0;
90.0 303.4 1.4178 0.02048 1350.5 2557.8 1363.3 1378.9 2742.1 3.2858 5.6772 90.0;
100. 311.1 1.4524 0.01803 1393.0 2544.4 1407.6 1317.1 2724.7 3.3596 5.6141 100;
110. 318.2 1.4886 0.01599 1433.7 2529.8 1450.1 1255.5 2705.6 3.4295 5.5527 110;
120. 324.8 1.5267 0.01426 1473.0 2513.7 1491.3 1193.6 2684.9 3.4962 5.4924 120.;
130. 330.9 1.5671 0.01278 1511.1 2496.1 1531.5 1130.7 2662.2 3.5606 5.4323 130.;
140. 336.8 1.6107 0.01149 1548.6 2476.8 1571.1 1066.5 2637.6 3.6232 5.3717 140.;
150. 342.2 1.6581 0.01034 1585.6 2455.5 1610.5 1000.0 2610.5 3.6848 5.3098 150.;
160. 347.4 1.7107 0.009306 1622.7 2431.7 1650.1 930.6 2580.6 3.7461 5.2455 160.;
170. 352.4 1.7702 0.008364 1660.2 2405.0 1690.3 856.9 2547.2 3.8079 5.1777 170.;
180. 357.1 1.8397 0.007489 1698.9 2374.3 1732.0 777.1 2509.1 3.8715 5.1044 180.;
190. 361.5 1.9243 0.006657 1739.9 2338.1 1776.5 688.0 2464.5 3.9388 5.0228 190.;
200. 365.8 2.036 0.005834 1785.6 2293.0 1826.3 583.4 2409.7 4.0139 4.9269 200.;
220.9 374.1 3.155 0.003155 2029.6 2029.6 2099.3 0 2099.3 4.4298 4.4298 220.9];
Table(:,12) = [];
Table(:,8) = [];
%Choose Menu
choice = 1;
value = 22;
output = interp1(Table(:, choice), Table, value)
6 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Foundation and Custom Domains についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!