多个变量的集成,其中每个变量是 R 中的一个向量?
Integration of multiple variables, where each variable is a vector in R?
我正在使用 R 来集成具有多个变量的函数,其中每个变量都是一个向量。如何获得矢量解决方案?
给定以下变量:
variable inputs
我需要集成以下功能:
t∝ = time till conversion, Ta = Ta upper limit, Ta-∆∝ = Ta lower, E∝ = activation energy, β=5, T0=1173
这是我使用的失败代码:
> library(readr)
> R_test_file <- read_csv("~/R test file.csv")
Parsed with column specification:
cols(
Conversion = col_double(),
`Activation Energy (kJ/mol)` = col_double(),
`Ta upper (Kelvin)` = col_double(),
`Ta lower (Kelvin)` = col_double()
)
> View(R_test_file)
> Ea = R_test_file$`Activation Energy (kJ/mol)`
> TaU = R_test_file$`Ta upper (Kelvin)`
> TaL = R_test_file$`Ta lower (Kelvin)`
> int.fun=function(Ea,T) (exp(-Ea/(8.314462*T)))/(5(exp(-Ea/(8.314462*1173))))
> integrate(int.fun, TaL, TaU)
你的函数定义有一些错误。更正版本:
int.fun <- function(T, Ea) (exp(-Ea/(8.314462*T)))/(5*(exp(-Ea/(8.314462*1173))))
您可以将功能集成为:
integrate(int.fun, Ea=-33.54, lower=296.1008, upper=553.4211)
如果你想对向量值进行积分,你可以这样做:-
Ea <- c(-33.54, -33.51, 7.24, 159.18)
TaU <- c(553.4211, 637.3555, 681.7970, 709.6234)
TaL <- c(296.1008, 553.4211, 637.3555, 681.7970)
lapply(seq_along(Ea), function(i) integrate(int.fun, Ea = Ea[i], lower = TaL[i], upper = TaU[i]))
我正在使用 R 来集成具有多个变量的函数,其中每个变量都是一个向量。如何获得矢量解决方案?
给定以下变量: variable inputs
我需要集成以下功能: t∝ = time till conversion, Ta = Ta upper limit, Ta-∆∝ = Ta lower, E∝ = activation energy, β=5, T0=1173
这是我使用的失败代码:
> library(readr)
> R_test_file <- read_csv("~/R test file.csv")
Parsed with column specification:
cols(
Conversion = col_double(),
`Activation Energy (kJ/mol)` = col_double(),
`Ta upper (Kelvin)` = col_double(),
`Ta lower (Kelvin)` = col_double()
)
> View(R_test_file)
> Ea = R_test_file$`Activation Energy (kJ/mol)`
> TaU = R_test_file$`Ta upper (Kelvin)`
> TaL = R_test_file$`Ta lower (Kelvin)`
> int.fun=function(Ea,T) (exp(-Ea/(8.314462*T)))/(5(exp(-Ea/(8.314462*1173))))
> integrate(int.fun, TaL, TaU)
你的函数定义有一些错误。更正版本:
int.fun <- function(T, Ea) (exp(-Ea/(8.314462*T)))/(5*(exp(-Ea/(8.314462*1173))))
您可以将功能集成为:
integrate(int.fun, Ea=-33.54, lower=296.1008, upper=553.4211)
如果你想对向量值进行积分,你可以这样做:-
Ea <- c(-33.54, -33.51, 7.24, 159.18)
TaU <- c(553.4211, 637.3555, 681.7970, 709.6234)
TaL <- c(296.1008, 553.4211, 637.3555, 681.7970)
lapply(seq_along(Ea), function(i) integrate(int.fun, Ea = Ea[i], lower = TaL[i], upper = TaU[i]))