我想用SciPy解决一个使用Newton-Raphson的非常简单的方程(开普勒方程)。然而,exectuing程序失败,出现以下错误信息:导入SciPy不起作用
return sc.optimize.newton(f, meanAnomaly, f_prime, args=(),
AttributeError: 'module' object has no attribute 'newton'
显然,虽然,我的Ubuntu 12.04下安装SciPy的。来自scipy.test():
NumPy version 1.5.1
NumPy is installed in /usr/lib/python2.7/dist-packages/numpy
SciPy version 0.9.0
SciPy is installed in /usr/lib/python2.7/dist-packages/scipy
Python version 2.7.2+ (default, Jan 21 2012, 23:31:34) [GCC 4.6.2]
nose version 1.1.2
有什么不对?这里是我的代码:
# File a
from b import *
print calculate_eccentric_anomaly(1,2)
# File b
def calculate_eccentric_anomaly(meanAnomaly, eccentricity):
import scipy.optimize as sc
def f(eccentricAnomaly):
return (eccentricAnomaly - eccentricity *
sc.sin(eccentricAnomaly) - meanAnomaly)
def f_prime(eccentricAnomaly):
return 1 - eccentricity * sc.cos(eccentricAnomaly)
return sc.optimize.newton(f, meanAnomaly, f_prime, args=(),
tol=1e-10, maxiter=50)
这是对的,愚蠢的初学者的错误。 – Ingo 2012-02-11 12:12:19