f <- function(x){(x/4)*exp(-x^2/8)}
# Definir la función ex
# Calcula el valor esperado de X
# Definir la función ex2
# Calcular la varianza de X
# Definir la función ex
ex <- function(x){x*f(x)}
# Calcula el valor esperado de X
expected_value <- integrate(ex, 0, Inf)$value
# Definir la función ex2
ex2 <- function(x){x^2*f(x)}
# Calcular la varianza de X
variance <- integrate(ex2, 0, Inf)$value - expected_value^2
test_function_definition("ex",
function_test = {
test_expression_result("ex(1)")
test_expression_result("ex(4)")
test_expression_result("ex(10)")
test_expression_result("ex(100)")
})
test_function("integrate", args = c("f", "lower", "upper"), eval = c(F, T, T))
test_object("expected_value")
test_function_definition("ex2",
function_test = {
test_expression_result("ex2(1)")
test_expression_result("ex2(4)")
test_expression_result("ex2(10)")
test_expression_result("ex2(100)")
})
test_function("integrate", args = c("f", "lower", "upper"), eval = c(F, T, T))
test_object("variance")