[英]How to plot a product function in R?
I'm trying a problem but first I have to plot in r
我正在尝试一个问题,但首先我必须在
r
绘图
(x+1)(x+2)...(x+n),
with n
being a fixed integer. n
是一个固定的整数。
Any idea how to create this routine? 知道如何创建这个例程吗?
Provided x
is greater than -1, this might be most efficiently computed by exploiting the relationship 如果
x
大于-1,则可以通过利用该关系来最有效地计算
(x + 1)*(x + 2)* ... *(x + n) = Gamma(x+n+1) / Gamma(x+1).
Gammas are computed internally in terms of their logarithms, so use these logs in the form of lgamma
: Gammas是根据它们的对数在内部计算的,所以以
lgamma
的形式使用这些日志:
f <- function(x, n) exp(lgamma(x+n+1) - lgamma(x+1))
A plot can then be obtained via curve
, for instance, as in 然后可以通过
curve
获得绘图,例如,如
curve(f(x,3), 0, pi)
You want something like this? 你想要这样的东西吗?
f <- function(x, n) {
return(prod(1/(x+(1:n))))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.