早教吧作业答案频道 -->数学-->
如何用Python和牛顿法解四元一次方程组我是试图用Sympy这个库来解决问题,却出错了.frommathimport*frompylabimport*#AvoidconfictbetwwensympyandmathimportsympyasspyfromWoyToolsimport*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这个库里关于使用牛顿法的语法规则就是要加引号的,我这么写在其他程序里没有问题
我是试图用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这个库里关于使用牛顿法的语法规则就是要加引号的,我这么写在其他程序里没有问题
▼优质解答
答案和解析
比较弱的问一下,你确定不是
'''
theta22=spy.Symbol('theta22')
theta33=spy.Symbol('theta33')
theta44=spy.Symbol('theta44')
theta55=spy.Symbol('theta55')
'''
这段有问题?
多了引号?或者.
'''
theta22=spy.Symbol('theta22')
theta33=spy.Symbol('theta33')
theta44=spy.Symbol('theta44')
theta55=spy.Symbol('theta55')
'''
这段有问题?
多了引号?或者.
看了 如何用Python和牛顿法解...的网友还看了以下:
数论题目(信息安全数学基础),thanksn是合数,p是n的素因数,证明:若p^a整除n,但p^( 2020-05-22 …
虚空藏菩萨咒下面拼音帮我翻出来虚空藏咒注音:ānǐ,luóshépí.qiánfúsuōshépí 2020-07-03 …
设M、N为两个随机事件,给出以下命题:(1)若M、N为互斥事件,且P(M)=15,P(N)=14, 2020-07-09 …
有关气体的:T、P、V、n之间的关系有具体的公式吗?当P、T相同时,V与n成正比,当T、V相同时, 2020-07-30 …
环数ξ=4,概率P=0.02,环数5=0.04,P=0.04..n次射击后为什么书上写预计有大约P( 2020-10-30 …
几何分布无记忆性证明中证:P{x=m+n|x>m}=P(X=m+n,x>m)/P{x>m}=P(X= 2020-10-31 …
X、Y分别服从参数为(n,p)(m,p)的二项分布,通过计算求出X+Y的分布我用的方法Z=X+YP( 2020-10-31 …
在直三棱柱中,已知底面积为s平方米,三个侧面面积分别为m平方米,n平方米,p平方米,则它的体积为s2 2020-11-27 …
在资金时间价值计算时,i和n给定,下列等式中正确的有().A.(F/A,i,n)=[(P/F,i,n 2021-01-14 …
1、在资金时间价值计算时,i和n给定,下列等式中正确的有?为什么?1、A(F/A,i,n)=[(P/ 2021-01-14 …