SymPy学习之Solvers

来源:互联网 发布:js常见兼容性问题 编辑:程序博客网 时间:2024/06/06 03:22
>>> from sympy import *>>> x, y, z = symbols('x y z')>>> init_printing(use_unicode=True)
A Note about Equations
#SymPy里的符号等式用的是Eq>>> Eq(x, y)x = y#方程求解函数默认右边等于0>>> solveset(Eq(x**2, 1), x){-1, 1}>>> solveset(Eq(x**2 - 1, 0), x){-1, 1}>>> solveset(x**2 - 1, x){-1, 1}
Solving Equations Algebraically
#solveset(equation, variable=None,domain=S.Complexes)>>> solveset(x**2 - x, x){0, 1}>>> solveset(x - x, x, domain=S.Reals)ℝ>>> solveset(sin(x) - 1, x, domain=S.Reals)⎧        π         ⎫⎨2⋅n⋅π + ─ | n ∊ ℤ⎬⎩        2          ⎭#无解或者多解>>> solveset(exp(x), x) # No solution exists∅>>> solveset(cos(x) - x, x) # Not able to find solution{x | x ∊ ℂ ∧ -x + cos(x) = 0}#root显示出各个解的频数>>> solveset(x**3 - 6*x**2 + 9*x, x){0, 3}>>> roots(x**3 - 6*x**2 + 9*x, x){0: 1, 3: 2}#solve解方程组>>> solve([x*y - 1, x - 2], x, y)[(2, 1/2)]
Solving Differential Equations
#定义f,g类型为function>>> f, g = symbols('f g', cls=Function)>>> f(x)f(x)>>> f(x).diff(x)d--(f(x))dx#求解微分方程>>> dsolve(f(x).diff(x)*(1 - sin(f(x))), f(x))f(x) + cos(f(x)) = C1

0 0
原创粉丝点击