class Equation(object):
def __init__(self, left, right, mode='latex'):
self.mode = mode
self.left = left
self.right = right
self._eq = sym.Eq(left, right)
self._latex = sym.latex(self._eq)
def __repr__(self):
if self.mode == 'latex':
return self._latex.__repr__()
elif self.mode == 'sympy':
return self._eq.__repr__()
def __str__(self):
if self.mode == 'latex':
return self._latex
elif self.mode == 'sympy':
return self.eq.__str__()
def eq(self):
return self._eq
def latex(self):
return self._latex
@property
def mode(self):
return self._mode
@mode.setter
def mode(self, val):
self._mode = val
@property
def left(self):
return self._left
@left.setter
def left(self, val):
self._left = sym
@property
def right(self):
return self._right
@right.setter
def right(self, val):
self._right = val
# end of class
sympy.Eq
。在Python中,=
运算符只是将变量赋值给SymPy表达式。在您的示例中,Python变量R_r
被赋值为SymPy表达式(c_1 + (c_2*x/G) + c_3*V)*G
。R_r
的变量上。R_r
的符号,并使用Eq(R_r, (c_1 + (c_2*x/G) + c_3*V)*G)
。http://docs.sympy.org/dev/modules/printing.html?highlight=sympy.printing#module-sympy.printing.latex