如何用Python 和牛顿法解四元一次方程组我是试图用Sympy这个库来解决问题,却出错了.from math import *from pylab import *#Avoid confict betwwen sympy and mathimport sympy as spyfrom WoyTools import *r1=300r2=1200r3=800r31=47
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/28 12:04:39
如何用Python 和牛顿法解四元一次方程组我是试图用Sympy这个库来解决问题,却出错了.from math import *from pylab import *#Avoid confict betwwen sympy and mathimport sympy as spyfrom WoyTools import *r1=300r2=1200r3=800r31=47
如何用Python 和牛顿法解四元一次方程组
我是试图用Sympy这个库来解决问题,却出错了.
from math import *
from pylab import *
#Avoid confict betwwen sympy and math
import sympy as spy
from WoyTools import *
r1=300
r2=1200
r3=800
r31=476.74
r32=1000
r4=800
r5=400
r6=1746.42
r7=600
theta1=pi/2
theta7=pi/2
alfa=float(float(100.02)/180.0*spy.pi)
gama=float(float(28)/180.0*spy.pi)
theta6=float(float(66.371)/180.0*spy.pi)
#set angle velocity of theta2
w1 = float(2*spy.pi)
#set angle acceleration of theta2
a1 = float(0/180.0*spy.pi)
ri=float(180/180.0*spy.pi)
theta5=float(323.13/180.0*spy.pi)
Ax=0
Ay=0
Ex=70
Ey=160
Fx=130
Fy=160
#guess value
theta2=float(float(84.982)/180.0*spy.pi)
theta3=float(float(22.676)/180.0*spy.pi)
theta4=float(float(159.626)/180.0*spy.pi)
theta5=float(float(152.334)/180.0*spy.pi)
time = 1
count=0
for t in arange(0,time+0.1,0.01):
theta1 = w1 * t + 0.5 * a1 * t * t
theta22=spy.Symbol('theta22')
theta33=spy.Symbol('theta33')
theta44=spy.Symbol('theta44')
theta55=spy.Symbol('theta55')
f1=r1*cos(theta1)+r2*spy.cos(theta22)+r31*spy.cos(theta33)*spy.cos(alfa)-r31*spy.sin(theta33)*spy.sin(alfa)+r4*cos(theta44)-r6*cos(theta6)
f2=r1*sin(theta1)+r2*spy.sin(theta22)+r31*spy.sin(theta33)*spy.cos(alfa)+r31*spy.cos(theta33)*spy.sin(alfa)+r4*sin(theta44)-r6*sin(theta6)
f3=r32*spy.cos(theta33)*spy.cos(gama)+r32*spy.sin(theta33)*spy.sin(gama)-r4*cos(theta44)+r5*cos(theta55)+r7
f4=r32*spy.sin(theta33)*spy.cos(gama)-r32*spy.cos(theta33)*spy.sin(gama)-r4*sin(theta44)+r5*sin(theta55)-r6*sin(theta6)
theta2,theta3,theta4,theta5 = spy.nsolve((f1,f2,f3,f4),(theta22,theta33,theta44,theta55),(theta2,theta3,theta4,theta5))
错误提示是在f1那里raise ValueError("Symbolic value, can't compute")
ValueError: Symbolic value, can't compute
有没有其他能用的解牛顿法的库或者如果用Sympy解决这个问题?
Sympy这个库里关于使用牛顿法的语法规则就是要加引号的,我这么写在其他程序里没有问题
如何用Python 和牛顿法解四元一次方程组我是试图用Sympy这个库来解决问题,却出错了.from math import *from pylab import *#Avoid confict betwwen sympy and mathimport sympy as spyfrom WoyTools import *r1=300r2=1200r3=800r31=47
比较弱的问一下,你确定不是
'''
theta22=spy.Symbol('theta22')
theta33=spy.Symbol('theta33')
theta44=spy.Symbol('theta44')
theta55=spy.Symbol('theta55')
'''
这段有问题?
多了引号?或者.