gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:32:56 25 4
gpt4 key购买 nike

在 R 中,我将如何为这样的等式找到(第一)根 x:

enter image description here

不幸的是,像这样的 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,那里的“根”出现在 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

关于r - 寻找具有 R 中没有封闭形式的积分的方程的根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30795810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com