Newton-Raphson을 사용하여 매우 간단한 방정식 (케플러 방정식)을 풀기 위해 SciPy를 사용하려고합니다. 그러나 프로그램을 exectuing하면 다음과 같은 오류 메시지와 함께 실패합니다 SciPy 가져 오기가 작동하지 않습니다.
return sc.optimize.newton(f, meanAnomaly, f_prime, args=(),
AttributeError: 'module' object has no attribute 'newton'
은 분명하지만, 나는 SciPy 우분투 12.04에 설치했다. 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
무엇이 잘못 되었나요? 여기에 내 코드입니다 : 당신은 sc
로 scipy.optimize
을 가져 오는
# 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