【问题标题】:sinh() returning inf in Rsinh() 在 R 中返回 inf
【发布时间】:2021-10-27 14:35:33
【问题描述】:

如果我这样做sinh(1000),我会得到Inf,这似乎是意料之中的,但我很想知道是否有任何方法可以克服这个问题?

我试过:format(round(sinh(1000), 2), nsmall = 2) 相信这是一个小数问题,但也许我的问题是概念性的,而不是技术性的?

我只是觉得奇怪的是 sinh(700) 运行良好,但在足够接近此值的数字上却失败了

【问题讨论】:

    标签: r scaling inf


    【解决方案1】:

    请参阅this 答案。 numeric R 中的对象只能变得这么大。对于大的x,逆sinh 大约是log(x) + log(2)

    > .Machine$double.xmax
    [1] 1.797693e+308
    > sinh(log(.Machine$double.xmax) + log(2))
    [1] 1.797693e+308
    > sinh(log(.Machine$double.xmax) + log(2) + 1e-10)
    [1] Inf
    

    一种常见的方法是在日志空间中工作。 log(sinh(x)) 对于大的x 大约是x - log(2)

    > log(sinh(700))
    [1] 699.3069
    > 700 - log(2)
    [1] 699.3069
    > log(sinh(700)) - 700 + log(2)
    [1] 5.495604e-14
    

    如果您澄清您要对大于 sinh(700) 的数字做什么,那么有人可能会有其他想法来解决您的问题。

    【讨论】:

    • 太棒了——感谢您的意见!
    猜你喜欢
    • 2021-04-09
    • 2018-06-28
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多