0
   integg <- function(t,a,b){  

   integrate(Vectorize(function(x){55}),lower=t-(a+b),upper=t-a)   
   }

I'm having what I think may be a simple problem.

I am integrating a constant over bounds that may vary.

If you were to think of this constant as a function, it only exists for values on the x-axis that are >= 0. I cant just set the lower bound == 0. Because there may be times when the lower bound is some value > 0.

It would probably be best to just write the constant as a function somehow.

A second problem I'm having is that I would like to make that value 55 as an object (x) which I can include as an argument to the function integg()

I am using Vectorize because that's the only way I know how to integrate constants.

4

1 に答える 1

1

あなたが説明したとおりにしないのはなぜですか。関数xに引数として追加しますintegg

integg <- function(t, a, b, intval) {
  u <- t - a
  l <- ifelse(u - b < 0, 0, u - b)
  integrate(Vectorize(function(foo, x) {55}), lower=l, upper=u, x=intval)
}

統合する関数が常に一定である場合は、独自の面積計算を記述できます。

integg2 <- function(t, a, b, intval) {
  u <- t - a 
  l <- ifelse(u - b < 0, 0, u - b)
  intval * (u - l)
}
于 2012-08-29T20:49:15.257 に答える