Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3.x如何处理不确定的形式,如0/0?_Python_Python 3.x_Math_Calculus - Fatal编程技术网

Python3.x如何处理不确定的形式,如0/0?

Python3.x如何处理不确定的形式,如0/0?,python,python-3.x,math,calculus,Python,Python 3.x,Math,Calculus,正如问题所述,我想知道python是如何计算方程的,比如 def indeterminate(x): return (x - math.sin(x)) / math.pow(x, 3) 当极限接近0时。我问是因为当我输入 >>> indeterminate(0.0000001) 0.17205356741102978 何处为 >>> indeterminate(0.00000001) 0.0 产量不是应该接近1/6吗?如果距离太近,ZeroDiv

正如问题所述,我想知道python是如何计算方程的,比如

def indeterminate(x):
    return (x - math.sin(x)) / math.pow(x, 3)
当极限接近0时。我问是因为当我输入

>>> indeterminate(0.0000001)
0.17205356741102978
何处为

>>> indeterminate(0.00000001)
0.0
产量不是应该接近1/6吗?如果距离太近,ZeroDivisionError消息不是比0.0更合适吗

我的另一个问题是如何计算实际的

indeterminate(0.00000001)

使用L'hopital规则的正确答案应该是1/6,但(0.166666…)而不是0.1720…

我刚刚意识到“不确定(0.00001)”比我加更多的零更准确。有人能给我解释一下吗?谢谢下面是一个例子,说明计算机中浮点数表示的有限精度可能会导致伪影:如果您期望的是“实际数”,那么您完全误解了浮点数是什么。代码中唯一精确表示为浮点的值是3。@sshashank124:
decimal
也不精确。它只是可配置的精度和小数。它不能防止舍入误差。使用50位数字可根据需要返回0.166666658333333336071657591591300437。在公式中使用mpmath很简单:公式变成
return(x-mp.sin(x))/mp.power(x,3)
,这意味着使用mpmath正弦函数和幂函数而不是数学。