首页 > 解决方案 > 如何解决 f(x, ...) 中的错误:未使用的参数 (x)

问题描述

f <- function(x) {((1/2)*((4*x)-1)*exp(-(1/2)*((3*x)+(2*x^2))))};
f   # order of arguments reversed 
h <- function(x) integrate(f, lower=0, upper=Inf, x=x)$value;
h 
g <- Vectorize(h);
g 
x <- seq(0,100)
plot(x,g(x), xlab="x", ylab="y", col="blue")

标签: rfunctionvariablesplotintegrate

解决方案


我认为你应该使用下面的代码

h <- function(x) integrate(f, lower=0, upper=Inf)$value;

推荐阅读