constant <- function(x){1}
integrate(constant,lower=1,upper=10)
これはおそらくばかばかしいほど単純なことではありませんが、これが機能しない理由についてはどうでしょうか。
定数の関数を書くべき別の方法はありますか?
constant <- function(x){1}
integrate(constant,lower=1,upper=10)
これはおそらくばかばかしいほど単純なことではありませんが、これが機能しない理由についてはどうでしょうか。
定数の関数を書くべき別の方法はありますか?
この関数を使用して、ベクトル化されていない関数を、以下を必要とするVectorize
種類の関数に変換できます。integrate
> constant <- function(x){1}
> Vconst <- Vectorize(constant)
> integrate(Vconst,lower=1,upper=10)
9 with absolute error < 1e-13
差出人?integrate
:
数値の最初の引数を取り、同じ長さの数値ベクトルを返すR関数。非有限要素を返すとエラーが発生します。
xと同じ長さのベクトルを返す必要があります。試す:
constant <- function(x){rep(1,length(x))}