Need help with homework (simple backwards interpolation)

4 views (last 30 days)
I want to calculate temperature of steam based on given enthalpy and pressure.
Example: https://imgur.com/a/u3rVOcD
The code should find temperature value (y axis) based on given enthalpy value (values in table) and pressure value (x axis). It is basically an backward interpolation, but with 2 variables.
Previously i have been using this code:
hnv_sek = 463.4
pk= 32
X_ZV = data_p_h(1,2:end)
Y_ZV = data_p_h(2:end,1)
Z_ZV = data_p_h(2:end,2:end)
x_ZV = pk
z_ZV = hnv_sek
fun_ZV = @(y_ZV)interp2(X_ZV,Y_ZV,Z_ZV,x_ZV,y_ZV)-z_ZV;
y_ZV = fzero(fun_ZV,mean(Y_ZV))
tnv_sek = y_ZV
interp2(X_ZV, Y_ZV, Z_ZV ,x_ZV , y_ZV)
end
And for values of data about and below 560, i have been getting this error (It was working fine with values that are high in table, until i get to low values. Any help would be greatly thanked for.):
Exiting fzero: aborting search for an interval containing a sign change
because NaN or Inf function value encountered during search.
(Function value at 37.0123 is NaN.)
Check function or try again with a different starting value.

Answers (1)

Torsten
Torsten on 20 Jan 2022
Specify the extrapolation value in interp2.
  2 Comments
Stefan Bogdanovic
Stefan Bogdanovic on 20 Jan 2022
Can you please define it more precisely? What do you mean by extrapolation value?
Torsten
Torsten on 20 Jan 2022
If the requested data y_zv is not between min(Y_ZV) and max(Y_ZV), interp2 together with your interpolation method 'linear' returns NaN.
Therefore, you have to specify a value to be returned for the cases y_zv < min(Y_ZV) or y_zv > max(Y_ZV).
Look into the documentation for interp2 for more details.

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!