解普通方程
from sympy import * x = Symbol('x') y = Symbol('y') print solve([2 * x - y - 3, 3 * x + y - 7],[x, y])
解微积分
from sympy import * n = Symbol('n') s = ((n+3)/(n+2))**n #无穷为两个小写o print limit(s, x, oo)
求定积分
from sympy import * t = Symbol('t') x = Symbol('x') m = integrate(sin(t)/(pi-t),(t,0,x)) n = integrate(m,(x,0,pi)) print n
解微分方程
#y' = 2xy 的通解 from sympy import * f = Function('f') x = Symbol('x') print dsolve(diff(f(x),x) - 2*f(x)*x,f(x)) #说明: f = Function('f') x = Symbol('x') #表示f(x)的导: diff(f(x), x, index) >>> diff(sin(x), x, 1) cos(x) dsolve(eq, f(x)) #第一个参数为微分方程(要先将等式移项为右端为0的形式) #第二个参数为要解的函数(在微分方程中)
矩阵化简
from sympy import * x1,x2,x3 = symbols('x1 x2 x3') a11,a12,a13,a22,a23,a33 = symbols('a11 a12 a13 a22 a23 a33') m = Matrix([[x1,x2,x3]]) n = Matrix([[a11,a12,a13],[a12,a22,a23],[a13,a23,a33]]) v = Matrix([[x1],[x2],[x3]]) f = m * n * v f[0] 化简, subs代入计算 print f[0].subs({x1:1, x2:1, x3:1})
Sympy 解方程
最新推荐文章于 2024-07-12 23:04:44 发布