寻找具有 R 中没有封闭形式的积分的方程的根

Finding of roots for an equation with an integral with no closed form in R

在 R 中,我将如何找到方程的(第一)根 x:

不幸的是,像这样的 R 代码不起作用,因为 R 中没有符号结构

g <- function(t) integrate(sin(t)/t,lower=0,upper=x)
root <- uniroot(g,(c(0,1)))$root

一般来说,我希望被积函数是任意函数,积分后可能有也可能没有解析解。此外,左侧可以是任意常数。

好吧,您对此类问题的语法有点不对劲。像

g <- Vectorize(function(x) integrate(function(t) sin(t)/t,lower=0,upper=x)$value-1)
root <- uniroot(g,c(0,1))$root

近一点。在这种情况下,R 不擅长在 0 处计算方程。您可以远离 0。此外,根据 Wolfram Alpha,"root" 出现在 1.06 处,这超出了您的搜索范围。这应该给出正确答案

g <- Vectorize(function(x) integrate(function(t) sin(t)/t,lower=0,upper=x)$value-1)
root <- uniroot(g,c(.01,1.5))$root
root
# [1] 1.06482