我如何将一个方程等效为零,然后求解它(目的是消除分母)。
y=(x**2-2)/3*x在Matlab中,这一工作是:
solution= solve(y==0,x)
但不是在蟒蛇。
发布于 2020-02-24 15:15:15
如果你只想消除分母,那么你可以把它分成分子和分母。如果方程已经以分数的形式出现,而你想要分子
>>> y=(x**2-2)/(3*x); y # note parentheses around denom, is that what you meant?
(x**2 - 2)/(3*x)
>>> numer(_)
x**2 - 2但是,如果方程以和的形式出现,那么您可以将它放在分母上,也许还可以用因子来识别分子因子,这些因子必须为零才能解决这个方程:
>>> y + x/(x**2+2)
x/(x**2 + 2) + (x**2 - 2)/(3*x)
>>> n, d = _.as_numer_denom(); (n, d)
(3*x**2 + (x**2 - 2)*(x**2 + 2), 3*x*(x**2 + 2))
>>> factor(n)
(x - 1)*(x + 1)*(x**2 + 4)
>>> solve(_)
[-1, 1, -2*I, 2*I]但是,在尝试求解之前,不必考虑分子的因素。但有时我发现它在处理特定方程时很有用。
如果你有一个方程的例子,在其他地方得到快速解,但不是在SymPy中,请张贴它。
发布于 2020-02-24 10:42:56
from sympy import *
x, y = symbols('x y')
y=(x**2-2)/3*x
# set the expression, y, equal to 0 and solve
result = solve(Eq(y, 0))
print(result)另一种解决办法是:
from sympy import *
x, y = symbols('x y')
equation = Eq(y, (x**2-2)/3*x)
# Use sympy.subs() method
result = solve(equation.subs(y, 0))
print(result)编辑(更简单):
from sympy import *
x, y = symbols('x y')
y=(x**2-2)/3*x
# solve the expression y (by default set equal to 0)
result = solve(y)
print(result)https://stackoverflow.com/questions/60373970
复制相似问题