SymPy nonlinsolve를 사용할 때 NameError가 발생합니다. 많은 게시물을 읽은 후 유형 및/또는 구문과 관련 될 수 있다고 생각하지만 정확한 원인을 찾지 못했습니다. 며칠 전에 sympy를 설치했으며 파이썬 버전은 파이썬 3.5.3 (기본값, Jan 19, 2017, 사전에 리눅스에 14시 11분 4초) [20170118 GCC 6.3.0]를 덕분에 당신은 nonlinsolve
이없는 SymPy의 버전을 사용하는 VilbjorgSymPy nonlinsolve NameError :
# Python 3 script , using SymPy library, parametrizatrion of the 3-sphere and rotations using quaternion multiplication
# python3 three_sphere.py
from sympy import *
def qmul(x0, x1, x2, x3, y0, y1, y2, y3):
z0 = x0*y0 - x1*y1 - x2*y2 - x3*y3
z1 = x0*y1 + x1*y0 + x2*y3 - x3*y2
z2 = x0*y2 - x1*y3 + x2*y0 + x3*y1
z3 = x0*y3 + x1*y2 - x2*y1 + x3*y0
return z0, z1, z2, z3
r1, s1, t1, r2, s2, t2 = symbols('r1, s1, t1, r2, s2, t2')
a0 = 2*r1/(1 + r1*r1 + s1*s1 + t1*t1)
a1 = 2*s1/(1 + r1*r1 + s1*s1 + t1*t1)
a2 = 2*t1/(1 + r1*r1 + s1*s1 + t1*t1)
a3 = (1 - r1*r1 - s1*s1 - t1*t1)/(1 + r1*r1 + s1*s1 + t1*t1)
b0 = 2*r2/(1 + r2*r2 + s2*s2 + t2*t2)
b1 = 2*s2/(1 + r2*r2 + s2*s2 + t2*t2)
b2 = 2*t2/(1 + r2*r2 + s2*s2 + t2*t2)
b3 = (1 - r2*r2 - s2*s2 - t2*t2)/(1 + r2*r2 + s2*s2 + t2*t2)
c0, c1, c2, c3 = qmul(a0, a1, a2, a3, b0, b1, b2, b3)
c0 = simplify(c0)
c1 = simplify(c1)
c2 = simplify(c2)
c3 = simplify(c3)
print(c0)
print(" ")
print(c1)
print(" ")
print(c2)
print(" ")
print(c3)
print(" ")
print(" ")
r3, s3, t3 = symbols('r3, s3, t3')
q0 = 2*r3/(1 + r3*r3 + s3*s3 + t3*t3)
q1 = 2*s3/(1 + r3*r3 + s3*s3 + t3*t3)
q2 = 2*t3/(1 + r3*r3 + s3*s3 + t3*t3)
q3 = (1 - r3*r3 - s3*s3 - t3*t3)/(1 + r3*r3 + s3*s3 + t3*t3)
#possibly syntax error here which causes NameError ??
soln = nonlinsolve([q0-c0, q1-c1, q2-c2, q3-c3], (r3, s3, t3))
# the idea is to have 4 equations : q0=c0, q1=c1. q2=c2. q3=c3 ; and solve for r3, s3 and t3 in terms of r1, s1, t1, r2, s2, t2
print(soln)
# http://docs.sympy.org/dev/tutorial/solvers.html
탱크, 대단히 '실제로는'nonlinsolve '가 sympy에 전혀 존재하지 않는 것 같습니다. (1.0.3 버전)이 특별한 문제는 아마도 해결되기 전에 적용될 인간 트릭을 필요로 할 것입니다. 이제 '해결'을 사용하면 컴퓨터가 여전히 쓰고있는 동안 열심히 노력하고 있습니다. 결론에 도달 할 것인지 확신 할 수 없습니다. –