Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

r - 如何在R中制作此功能?(How to craft this function in R?)

I am currently trying to write a function that estimates energy expenditure of some lizards through E = e21.44 * (e(8.74901^10?20 / (1.3806488*10?23 *T). T in the equation is equal to the temperature in Kelvin. I know that if I were to plug in a temperature of 20oC the function should give me an output of about 0.829. However, when I run the function (see below) I get 2.628622e-121. I believe it's the way I am stating how temperature is converted from Celsius to Kelvin is incorrect and I am currently stuck on it.

(我目前正在尝试编写一个函数,该函数通过E = e21.44 *(e(8.74901 ^ 10-20 /(1.3806488 * 10-23 * T))估算一些蜥蜴的能量消耗。等式中的T等于温度在开尔文(Kelvin),我知道如果插入20oC的温度,该函数应给我约0.829的输出。但是,当我运行该函数(见下文)时,我得到2.628622e-121。我正在说明温度是如何从摄氏温度转换为开尔文的,这是不正确的,我目前仍然坚持。)

TempKelvin <- 273.15
Energy = function(TempKelvin = 273.15 {
exp(24.11) * exp(-8.74901*10^20 / (1.3806488*10^-23 * (T + TempKelvin)))
}
Energy(T = 28)
  ask by Wheresbreakfast translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Welcome to SO!

(欢迎来到SO!)

If you're given Celsius, how about converting to Kelvin first and then doing the formula, then you can narrow in on the problem from there.

(如果给定了摄氏温度,那么先转换为开尔文,然后再进行公式计算,然后可以从那里缩小问题范围。)

I'm guessing there's a parentheses problem or a sign problem with the -8.7.. vs 8.7.. .

(我猜-8.7..8.7..存在括号问题或符号问题。)

Energy <- function(temp_c) {
  temp_k <- temp_c + 273.15
  energy <- exp(21.44) * exp(-8.74901*10^20 / (1.3806488*10^-2 * temp_k))
  print(energy)
  }
Energy(28)
#[1] 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...