两个参数的函数的积分其中一个参数是随机向量

时间:2022-02-02 19:30:46

I have a function func (in R) of 2 variables defined like this (just an example):

我有一个函数func(在R中)由两个变量定义,像这样(只是一个例子):

func <- function(t,gam){return(exp(-t/2)*(t+1)^gam)}

The second argument gam will be estimated from 2 different sample so basically gam is a vector of length 2. What I want to receive is the integration of this function for t: 0->Inf when gam is known.

第二个参数gam将从两个不同的样本进行估计,所以gam基本上是一个长度为2的向量。我想要得到的是当gam被知道时,这个函数对t: 0->Inf的积分。

I tried few ways but could not get a vector of values from integration. Any advice will be very much appreciated. Thanks a lot.

我尝试了一些方法,但是无法从积分中得到一个值向量。非常感谢您的建议。非常感谢。

1 个解决方案

#1


0  

Need to use sapply to deliver the two item vector (separately) to integrate:

需要使用sapply分别交付两个项目向量进行集成:

sapply( gam, function(x) integrate( func, lower=0,upper=Inf,  gam=x)$value )

Example:

例子:

> sapply( c(.5,1), function(x) integrate( func, lower=0,upper=Inf,  gam=x)$value )
[1] 3.311359 6.000000

#1


0  

Need to use sapply to deliver the two item vector (separately) to integrate:

需要使用sapply分别交付两个项目向量进行集成:

sapply( gam, function(x) integrate( func, lower=0,upper=Inf,  gam=x)$value )

Example:

例子:

> sapply( c(.5,1), function(x) integrate( func, lower=0,upper=Inf,  gam=x)$value )
[1] 3.311359 6.000000