您好我是python的新手,我正在尝试使用未知变量求解一组方程式,方程式在下面的代码中
from __future__ import division
import sympy as sy
import math
#Global Variables indepenedant of calculations
Tc = 9.25
Ic = 340*10-6
Tb = 6.2
I = 2 *Ic
alpha = 2*10**-2
thickness = 100*10**-10
L0 = 2.44*10**-8
electrical_resist = 0.5*10**-2
sigma = 1 / electrical_resist
k = sigma*L0*Tc
A = 1
B = 1
#set of problems to solve
r0 = sy.symbols('r0')
LHS=(I/(alpha*thickness))**2 * electrical_resist
RHS = -k*((r0**2)*((A*math.e**Tc)+(B*math.e**0)))+(alpha/thickness) * (r0**2) * (Tc - Tb)
print sy.nsolve(LHS==RHS, 0.002)
但我一直收到错误
2444 if isinstance(f, Equality):
2445 f = f.lhs - f.rhs
-> 2446 f = f.evalf()
2447 syms = f.free_symbols
2448 if fargs is None:
AttributeError: 'bool' object has no attribute 'evalf'
非常感谢任何帮助。
答案 0 :(得分:0)
LHS==RHS
创建一个布尔值,如果LHS完全等于RHS则为True,否则为False。 nsolve
和SymPy中的其他求解函数假设表达式等于零,因此请使用nsolve(LHS - RHS, 0.002)
。另请参阅http://docs.sympy.org/latest/tutorial/gotchas.html#equals-signs。