Skip to content

Instantly share code, notes, and snippets.

@etoyoda
Created May 29, 2021 12:12
Show Gist options
  • Save etoyoda/29f2ec36bf9902301c4cd57535a7d76a to your computer and use it in GitHub Desktop.
Save etoyoda/29f2ec36bf9902301c4cd57535a7d76a to your computer and use it in GitHub Desktop.
inverse function of Tetens formula
def tetens t
6.112 * Math.exp(17.67 * (t - 273.15) / (t - 29.65))
end
def invtetens e
k = Math.log(e/6.112) / 17.67
0.05 * (-5463.0 + 593.0 * k) / (-1.0 + k)
end
(0..50).each {|tc|
t = tc + 273.15
e = tetens(t)
rt = invtetens(e)
rtc = rt - 273.15
printf "%10.2f %10.2f %10.2f\n", tc, e, rtc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment