一、方程式
SymPy中方程式不是用“=”表示相等,而是使用Eq
from sympy import * x, y, z = symbols(‘x y z‘) init_printing(use_unicode=True) Eq(x, y)
还可以这样表达
solveset(Eq(x**2, 1), x) solveset(Eq(x**2 - 1, 0), x) #这里默认等于0 solveset(x**2 - 1, x)
求解方程是要函数是solveset,使用语法是solveset(equation, variable=None, domain=S.Complexes),分别是等式(默认等于0,),变量,定义域。
请注意,函数solve
也可以用于求解方程式,solve(equations, variables)
solveset(x**2 - x, x) solveset(x - x, x, domain=S.Reals) solveset(sin(x) - 1, x, domain=S.Reals)
如果是无解,返回空,如果找不到解,返回表达式
solveset(exp(x), x) # No solution exists solveset(cos(x) - x, x) # Not able to find solution
求解线性方程组linsolve
linsolve([x + y + z - 1, x + y + 2*z - 3 ], (x, y, z))
只写前面的系数
linsolve(Matrix(([1, 1, 1, 1], [1, 1, 2, 3])), (x, y, z))
原文:https://www.cnblogs.com/cgmcoding/p/14680457.html