我想用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