I need to set up a library

2 ビュー (過去 30 日間)
Truman Cassady
Truman Cassady 2018 年 10 月 13 日
コメント済み: Walter Roberson 2018 年 10 月 13 日
I am doing some thermodynamics things, and I would like to have a function that when given either two of temperature pressure or specific volume will interpolate for the other intensive property from the 100x3 matrix I have entered into the matlab function code. How could I create the logic for accepting 2 of the three input variables? I think I could figure out the interpolation part myself. Thank you so much!

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 10 月 13 日
... However, for something with only two possible options, just coding your own parsing might be easier.
  2 件のコメント
Truman Cassady
Truman Cassady 2018 年 10 月 13 日
Thank you, I have decided to make three different fucntions for the three different cases(having either T,P or P,v or v,P). So to start on the T,P. within the function how would I scan the matrix of data for the index that is closest to the input variables? function fd=vbar(Temp,Pres) if Temp( find the two indices in which Temp is between in the 100x3 matrix of Temp,Pres,Vbar) then interpolate between those indices.
Walter Roberson
Walter Roberson 2018 年 10 月 13 日
If you have a 100x3 matrix whose columns are temperature, pressure, and volume, then you do not have a regular grid of data, and more complicated (slower) interpolation methods must be used.
The general method is to use (for example)
first_var_col = 2;
second_var_col = 3;
resulting_var_col = 1;
first_var_value = ... %input value for first variable
second_var_value = ... %input value for second variable
estimated_result = griddata( YourData(:, first_var_col), YourData(:, second_var_col), YourData(:, resulting_var_col), first_var_value, second_var_value );
This will be a comparatively expensive operation. If you were potentially going to do multiple queries, then it would be a little more efficient to instead use scatteredInterpolant() and save the resulting object, and then next time you got the same kind of query, pull back the saved object instead of building a new scatteredInterpolant.
If it happened that your data could be arranged in a 10 x 10 regular grid, then faster querying could be done in one of the cases... but only one.

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

カテゴリ

Help Center および File ExchangeThermodynamics and Heat Transfer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by