Need help with homework (simple backwards interpolation)
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Torsten
2022-1-20
Specify the extrapolation value in interp2.
2 个评论
Torsten
2022-1-20
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!