本文介绍了python正弦和余弦精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何提高python正弦和余弦精度?例如,我想使用跟随代码(对于随机复数x只需计算y = cos(acos(x))):
How to improve python sine and cosine precision? For example I want to use follow code (just calculate y = cos(acos(x)) for a random complex vector x):
import numpy as np
N = 100000
x = np.zeros(N)+1j*np.zeros(N)
for k in range(0,N):
x[k] = np.random.normal(0,500)+1j*np.random.normal(0,500)
y = np.cos(np.arccos(x))
m= np.max(np.abs(x))
print np.max(np.abs(x-y)/m)
y 必须等于 x .但是我的区别大约是 1E-9 .我觉得太大了.例如,对于相同的测试,matlab返回的小于1E-15 .有什么方法可以提高python的精度吗?谢谢!
y must be equal x. But my difference is approx 1E-9. I think is too big. For example matlab returns less than 1E-15 for the same test. There is some way to improve python precision? Thanks!
推荐答案
重新安装python后,问题消失了.感谢您的评论
Problem is disappear after python reinstall. Thanks for comments
这篇关于python正弦和余弦精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!