![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Sympy
文章平均质量分 81
Triagen
烟花三月江南游,年少何忧?素衣写风流,邂逅佳人一点羞。
展开
-
SymPy学习之Logic Module
Forming logical expressions>>> from sympy import *>>> x, y = symbols('x,y')>>> y | (x & y)Or(And(x, y), y)>>> x | yOr(x, y)>>> ~xNot(x)>>> x >> yImplies(x, y)>>> x << yImplies(y, x)>>> (原创 2017-03-18 09:40:53 · 710 阅读 · 0 评论 -
sympy学习之Matrices
>> from __future__ import division>>> from sympy import *#行列>>> Matrix([[1, -1], [3, 4], [0, 2]])⎡1 -1⎤⎢ ⎥⎢3 4 ⎥⎢ ⎥⎣0 2 ⎦#列>>> Matrix([1, 2, 3])⎡1⎤⎢ ⎥⎢2⎥⎢ ⎥⎣3⎦#行>>> Matrix原创 2017-03-15 10:53:25 · 1442 阅读 · 0 评论 -
SymPy学习之Advanced Expression Manipulation
Understanding Expression Trees>>> from sympy import *>>> x, y, z = symbols('x y z')>>> expr = x**2 + x*y>>> srepr(expr) #使用srepr查看内部保存形式Add(Pow(Symbol('x'), Integer(2)), Mul(Symbol('x'), Symbo原创 2017-03-15 10:55:21 · 908 阅读 · 0 评论 -
SymPy学习之Gotchas and Pitfalls
Equals Signs (=)Single Equals Sign#单个等号用于赋值>>> from sympy.abc import x, y>>> a = x - y>>> print(a)x - yDouble Equals Signs#双等号用于判断内部结构相等>>> (x + 1)**2 == x**2 + 2*x + 1False>>> (x +原创 2017-03-15 10:56:57 · 1213 阅读 · 0 评论 -
SymPy学习之Numerical evaluation
Basics#N(expr, )函数与sympify(expr).evalf()等价>>> from sympy import *>>> N(sqrt(2)*pi)4.44288293815837>>> (sqrt(2)*pi).evalf()4.44288293815837#额外的参数用于确认精确度>>> N(sqrt(2)*pi, 5)4.4429>>> N(sqrt(2原创 2017-03-15 10:59:10 · 1336 阅读 · 0 评论 -
SymPy学习之Concrete Mathematics
Sum>>> from sympy.abc import i, k, m, n, x>>> from sympy import Sum, factorial, oo, IndexedBase, Function>>> Sum(k, (k, 1, m))Sum(k, (k, 1, m))>>> Sum(k, (k, 1, m)).doit()m**2/2 + m/2>>> Sum(k原创 2017-03-15 10:59:48 · 470 阅读 · 0 评论 -
SymPy学习之Numeric Computation
Subs/evalf>>> from sympy import *>>> from sympy.abc import x>>> expr = sin(x)/x>>> expr.evalf(subs={x: 3.14})0.000507214304613640Lambdify>>> from sympy import *>>> from sympy.abc import x原创 2017-03-15 11:00:19 · 646 阅读 · 0 评论 -
SymPy学习之Elementary
sympy.functions.elementary.complexesre#返回复数实数部分>>> from sympy import re, im, I, E>>> from sympy.abc import x, y>>> re(2*E)2*E>>> re(2*I + 17)17>>> re(2*I)0>>> re(im(x) + x*I + 2)2#as_原创 2017-03-17 12:57:13 · 2389 阅读 · 0 评论 -
SymPy学习之Geometry Module
Example Usage>>> from sympy import *>>> from sympy.geometry import *>>> x = Point(0, 0)>>> y = Point(1, 1)>>> z = Point(2, 2)>>> zp = Point(1, 0)>>> Point.is_collinear(x, y, z) #判断共线True>>原创 2017-03-17 12:57:57 · 1246 阅读 · 0 评论 -
SymPy学习之Solvers
>>> 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){原创 2017-03-15 10:52:55 · 1283 阅读 · 0 评论 -
SymPy学习之Calculus
>> from sympy import *>>> x, y, z = symbols('x y z')>>> init_printing(use_unicode=True)Derivatives#导数>>> diff(cos(x), x)-sin(x)>>> diff(exp(x**2), x) ⎛ 2⎞ ⎝x ⎠2⋅x⋅ℯ#多次求导>>> dif原创 2017-03-15 10:52:04 · 411 阅读 · 0 评论 -
SymPy学习之Simplification
Simplification>>> from sympy import *>>> x, y, z = symbols('x y z')>>> init_printing(use_unicode=True)simplify#对式子进行化简>>> simplify(sin(x)**2 + cos(x)**2)1>>> simplify((x**3 + x**2 - x - 1原创 2017-03-15 10:50:53 · 1073 阅读 · 0 评论 -
SymPy学习之Introduction
与Python内置函数的区别#内置函数>>> import math>>> math.sqrt(9)3.0>>> math.sqrt(8)2.82842712475#sympy>>> import sympy>>> sympy.sqrt(3)sqrt(3)>>> sympy.sqrt(8)2*sqrt(2)#sympy保留了原式,且能自动进行部分化简符号表达原创 2017-03-05 23:40:17 · 508 阅读 · 0 评论 -
SymPy学习之Basic Operations
>>> from sympy import *>>> x, y, z = symbols("x y z")Substitution#多个参数>>> expr = x**3 + 4*x*y - z>>> expr.subs([(x, 2), (y, 4), (z, 0)])40Converting Strings to SymPy Expressions>>> str原创 2017-03-05 23:40:57 · 456 阅读 · 0 评论 -
SymPy学习之Gotchas
一个问题>>> x = symbols('x')>>> expr = x + 1>>> x = 2>>> print(expr)x + 1#SymPy有自己的变量,通过symbols函数将Python变量名与自己的变量名相关联,因此x = 2只是将Python变量x与2关联,不影响SymPy的内部变量举个例子:>>> a,b = symbols('b a')#将python变量a,原创 2017-03-05 23:41:55 · 571 阅读 · 0 评论 -
SymPy学习之Printing
Printers一些可用的printersstrsreprASCII pretty printerUnicode pretty printerLaTeXMathMLDotSetting up Pretty Printing>>> from sympy import init_printing>>> init_printing() #根据环境选择输出方式>>>原创 2017-03-05 23:42:28 · 1851 阅读 · 0 评论 -
SymPy学习之Plotting Module
#用extend将一张图添加到另一张图上面>>> from sympy import symbols>>> from sympy.plotting import plot>>> x = symbols('x')>>> p1 = plot(x*x)>>> p2 = plot(x)>>> p1.extend(p2)>>> p1Plot object containing:[0]: c原创 2017-03-19 23:42:52 · 3900 阅读 · 0 评论 -
SymPy学习之Matrices (linear algebra)
Creating Matrices>>> from sympy.interactive.printing import init_printing>>> init_printing(use_unicode=False, wrap_line=False, no_global=True)>>> from sympy.matrices import Matrix, eye, zeros, one原创 2017-03-20 00:06:25 · 2231 阅读 · 0 评论 -
SymPy学习之Basic functionality of the module
Basic functionalityDivision#多项式除法>>> f = 5*x**2 + 10*x + 3>>> g = 2*x + 2>>> q, r = div(f, g, domain='QQ')>>> q5*x 5--- + - 2 2>>> r-2>>> (q*g + r).expand() 25*x + 10*x + 3原创 2017-03-20 00:16:26 · 587 阅读 · 0 评论 -
SymPy学习之Polynomials Manipulation Module Reference
sympy.polys.polytools.poly(expr, *gens, **args)>>> poly(x*(x**2 + x - 1)**2)Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')sympy.polys.polytools.degree(f, *gens, **args)#指定变量最大次数>>>原创 2017-03-20 00:24:21 · 1172 阅读 · 0 评论 -
SymPy学习之Symbolic Integrals
Examples>>> from sympy import *>>> init_printing(use_unicode=False, wrap_line=False, no_global=True)>>> x = Symbol('x')>>> integrate(x**2 + x + 1, x) 3 2x x-- + -- + x3 2>>> integra原创 2017-03-17 13:03:55 · 631 阅读 · 0 评论