python - Python; 求解等于零的方程
问题描述
我如何将方程等同于零然后求解(目的是消除分母)。
y=(x**2-2)/3*x
在 Matlab 这工作:
solution= solve(y==0,x)
但不是在python中。
解决方案
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)
推荐阅读
- javascript - 如何访问 Ionic React 中自定义列表项的属性?
- recursion - 迭代中递归模式的更多技术
- node.js - 创建或更新 dynamodb
- java - 使用 StringBuilder 和 PrintWriter 将密码写入 txt 文件(不是 StringWriter)
- apache-spark - 将最后一位数字分隔到pyspark中的新列
- python - 无法在原始套接字上接收 GRE 数据包
- reactjs - React Redux:如何在屏幕上动态呈现数据?
- typescript - 当我使用 babel 转换 typescript 时,它将导入放在页面顶部,但是必须在导入之前初始化一个变量
- reactjs - 将页码添加到 url - 反应分页
- amazon-web-services - 更新被 lex 测试命中的 lambda 函数的最快方法是什么?