Ala*_*din 1 python matplotlib solver sympy
假设我有一个方程,例如
10 * x ** 2 - 7 * x + 3 == 2 * y + y ** 2
我想求解y,然后绘制从 0 到 1的y对比图。我如何在 Python 中做到这一点?xx
我知道如何在 Mathematica 中执行此操作,但我正在迁移到 Python。在 Mathematica 中只有一行
Plot[y /. Solve[10 x^2 - 7 x + 3 == 2 y + y^2, y], {x, 0, 1}]
Run Code Online (Sandbox Code Playgroud)
小智 7
SymPy 是一个符号数学包:
https://docs.sympy.org/latest/modules/solvers/solvers.html https://www.tutorialspoint.com/sympy/sympy_quick_guide.htm
from sympy import solve, plot
from sympy.abc import x, y
ans = solve(10 * x ** 2 - 7 * x + 3 - (2 * y + y ** 2), y)
print(ans)
Run Code Online (Sandbox Code Playgroud)
回答:
[-sqrt(10*x**2 - 7*x + 4) - 1, sqrt(10*x**2 - 7*x + 4) - 1]
Run Code Online (Sandbox Code Playgroud)
然后您可以使用任何绘图包或 sympy.plot 进行绘图:
plot(ans[0])
plot(ans[1])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
310 次 |
| 最近记录: |