matlab中erf/erfc函数的问题

problems with the erf/erfc function in matlab

我对 Matlab 的 erf/erfc 函数的准确性有疑问。

我们知道,如果x是无穷大,erf(x)只等于1。

然而,在 Matlab 中,令我惊讶的是 erf(6) 已经等于 1 而 6 甚至不是很大!

erfc(x) 更好一些,因为 erfc(27) 是非零,而 erfc(28) 是零。

有没有办法提高这个函数的数值性能?即,增加 erf(x) 的值范围以获得不完全为 1 的值? (对于 erfc 也是 0?)

如果您有符号数学工具箱,您将处理 double precision floating point. erfc performs differently because values are more closely spaced around 0 than 1. You need to represent your values with a different number system if you really need more precision (it's not clear to me why you would). Try using variable precision arithmetic。尝试

erf(vpa(6))

其中returns符号值0.99999999999999997848026328750109。您将需要使用 digits as the argument gets larger. And of course if you convert the results back to floating point with double 您将失去所有额外的精度。