I would like to find the optimum value of a
for the following integration which is a function of x
integrand <- function(x,a) {
D=a/((x+1)*sqrt(x+a))
D
}
I can do the integration for fixed value of a
. For example, if a=5
> integrate(integrand,0,5,a=5)$value
[1] 3.490687
But I want to find the optimum value using the optim()
function in R or any available built-in optimization function. I have tried the following code, unfortunately it is not working,
optim(5,integrate(integrand, lower = 0, upper = 5))
Any help is appreciated.
You can use the 'optimize' function, which is ideal for one-parameter optimization:
optimize(f = integrand, interval = c(0, 5), a = 5)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.