如何表达
> (exp(17.118708 + 4.491715 * -2)/-67.421587)^(-67.421587)
结果
[1] NaN
,而
> -50.61828^(-67.421587)
应该基本上有相同的结果,给我
[1] -1.238487e-115
这让我发疯,我花了几个小时寻找错误。 " -2",在这种情况下,是函数的参数。我真的无法想到解决方案。谢谢你的帮助!
编辑:
当我添加括号
时,我看到了> (-50.61828)^(-67.421587)
它也会导致
[1] NaN
...但这并不能解决我的问题。
答案 0 :(得分:3)
这是因为根据C99标准实施pow
。
更不用说OP的例子:(-50.61828)^(-67.421587)
,数学上合理的(-8)^(1/3) = -2
在R中不起作用:
(-8)^(1/3)
# [1] NaN
引自?"^"
:
Users are sometimes surprised by the value returned, for example
why ‘(-8)^(1/3)’ is ‘NaN’. For double inputs, R makes use of IEC
60559 arithmetic on all platforms, together with the C system
function ‘pow’ for the ‘^’ operator. The relevant standards
define the result in many corner cases. In particular, the result
in the example above is mandated by the C99 standard. On many
Unix-alike systems the command ‘man pow’ gives details of the
values in a large number of corner cases.
我在Ubuntu LINUX上,所以可以帮助获得man power
打印在这里的相关部分:
If x is a finite value less than 0, and y is a finite noninteger, a
domain error occurs, and a NaN is returned.
答案 1 :(得分:1)
据我所知,-50.61828^(-67.421587)
正在评估-(50.61828^(-67.421587))
。 (-50.61828)^(-67.421587)
也会导致NaN。