R中集成功能的优化 [英] Optimization of an integrated function in R

查看:104
本文介绍了R中集成功能的优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为以下积分找到a的最佳值,这是x

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
        }

我可以对a的固定值进行积分.例如,如果a = 5

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

但是我想使用R中的optim()函数或任何可用的内置优化函数来找到最佳值.我尝试了以下代码,很遗憾,它无法正常工作,

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))

感谢您的帮助.

推荐答案

您可以使用优化"功能,该功能非常适合单参数优化:

You can use the 'optimize' function, which is ideal for one-parameter optimization:

optimize(f = integrand, interval = c(0, 5), a = 5)

这篇关于R中集成功能的优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆