当用户使用下拉菜单选择要查找的项目时,简单谐波运动中涉及所选项目的所有方程式将重新排列,并以搜索的值作为主题。我使用Sympy方程重新排列了方程。是否有办法将值细分为现在重新排列的方程式或将Sympy方程式更改为Sympy表达式?
这是您可能会发现有用的代码部分:
listCounter = 0
counter = 0
equationsWithSearched = []
symbolsListWithNeededValue = []
print ("value is", var.get()) #listCounter keeps track of the lists within the 2d array
#symbols
a,f,x,A,t,v,vmax,amax,Tm,m,k,Tp,l,g,F,Ek,Ep = sp.symbols('a,f,x,A,t,v,vmax,amax,Tm,m,k,Tp,l,g,F,Ek,Ep')
#expressions
aExp = -((2*sp.pi*f)**2)*x
xExp = A*sp.cos(2*sp.pi*f*t)
vExp = 2*sp.pi*f*sp.sqrt(A**2-x**2)
vmaxExp = 2*sp.pi*f*A
amaxExp = ((2*sp.pi*f)**2)*A
TmExp = 2*sp.pi*sp.sqrt(m/k)
TpExp = 2*sp.pi*sp.sqrt(l/g)
F_Exp = -k*x
EkExp = 0.5*m*v**2
EpExp = 0.5*k*x**2
#equations
aEq = sp.Eq(a, aExp)
xEq = sp.Eq(x, xExp)
vEq = sp.Eq(v, vExp)
vmaxEq = sp.Eq(vmax, vmaxExp)
amaxEq = sp.Eq(amax, amaxExp)
TmEq = sp.Eq(Tm, TmExp)
TpEq = sp.Eq(Tp, TpExp)
F_Eq = sp.Eq(F, F_Exp)
EkEq = sp.Eq(Ek, EkExp)
EpEq = sp.Eq(Ep, EpExp)
sp.pprint(sp.solve(aEq, x))
functionsList = [aEq, xEq, vEq, vmaxEq, amaxEq, TmEq, TpEq, F_Eq, EkEq, EpEq]
for each in functionsList:
symbolsList.append(each.free_symbols)
print('length of symbolsList', len(symbolsList))
for each in symbolsList:
listCounter += 1
print(list(each))
while counter < len(list(each)):
print(list(each)[counter])
if str(list(each)[counter]) == var.get():
print('True')
print(functionsList[listCounter-1])
equationsWithSearched.append(functionsList[listCounter-1])
symbolsListWithNeededValue.append(each)
counter += 1
else:
counter += 1
counter = 0