<<

SymPy Cheatsheet (http://sympy.org)

Basics Geometry Examples Sympy help: help(function) Points: a = Point(xcoord, ycoord) Find 100 digits of πe: Declare symbol: x = Symbol(’x’) Lines: l = Line(pointA, pointB) (pi**E).n(100) Substitution: expr.subs(old, new) Circles: = Circle(center, radius) Numerical evaluation: expr.evalf() Triangles: t = Triangle(a, b, c) Expand (x + y)2(x − y)(x2 + y): Expanding: expr.expand() Area: object.area ((x + y)**2 * (x - y) * (x**2 + y)).expand() Common denominator: ratsimp(expr) Intersection: intersection(a, b) 1 x sin x − 1 Simplify expression: simplify(expr) Checking tangency: c.is_tangent(l) Simplify + : x x2 − 1 simplify((1/x) + (x * sin(x) - 1)/(x**2 - 1)) Constants Numbers types Plotting Check if line passing through points (0, 1) and (1, 1) π: pi (Z): (x) Plot: Plot(f, [a, b]) is tangent to circle with center at (5, 5) and radius 3: e: E Rationals (Q): Rational(p, q) Zoom: +/−: /F or PgUp/PgDn or Numpad +/- Circle(Point(5,5), 3).is_tangent( ∞: oo Reals (R): Float(x) Rotate X,Y axis: Arrow Keys or WASD Line(Point(0,1), Point(1,1))) i: I Rotate Z axis: Q and E or Numpad 7 and 9 View XY: F1 Find roots of x4 − 4x3 + 2x2 − x = 0: View XZ: F2 Basic funtions solve(x**4 - 4*x**3 + 2*x**2 - x, x) View YZ: F3 Trigonometric: sin cos tan cot View Perspective: F4 Solve the equations system: x + y = 4, xy = 3: Cyclometric: asin acos atan acot Axes Visibility: F5 solve([x + y - 4, x*y - 3], [x, y]) Hyperbolic: sinh cosh tanh coth Axes Colors: F6 Area hyperbolic: asinh acosh atanh acoth Screenshot: F8 √ Calculate limit of the sequence n n: Exponential: exp(x) Exit plot: ESC Square root: sqrt(x) limit(n**(1/n), n, oo)

Logarithm (logb a): log(a, b) Discrete math |x| : log(a) Calculate left-sided limit of the function x in 0: Gamma (Γ(x)): gamma(x) (n!): ( ) factorial(n) limit(abs(x)/x, x, 0, dir=’-’) Absolute value: abs(x) n ∑ coefficient k : binomial(n, k) ∑ b Calculate the sum 100 n2: Sum ( n=∏a expr): (expr, (n, a, b)) n=0 b summation(n**2, (n, 0, 100)) Calculus Product ( n=a expr): product(expr, (n, a, b)) ∑∞ lim f(x): limit(f, x, a) Calculate the sum 1 : x→a Linear algebra n=0 n2 lim f(x): limit(f, x, a, dir=’-’) summation(1/n**2, (n, 0, oo)) x→a− Matrix definition: m = Matrix([[a, b], [c, d]]) ∫ lim f(x): limit(f, x, a, dir=’+’) 3 x→a+ Determinant: m.det() Calculate the integral cos x dx: d integrate(cos(x)**3, x) dx f(x): diff(f, x) Inverse: m.inv() ∂ f(x, y): diff(f, x) × ∫∂x Identity matrix n n: eye(n) ∫ ∞ × Calculate the integral dx : ∫ f(x) dx : integrate(f, x) Zero matrix n n: zeros(n) 1 x2 b Ones matrix n × n: ones(n) integrate(1/x**2, (x, 1, oo)) a f(x) dx : integrate(f, (x, a, b)) Taylor (at a, deg n) f.series(x, a, n) Find 10 terms of series expansion of 1 at 0: Printing 1−2x (1/(1 - 2*x)).series(x, 0, 10) Equations LAT X print: print latex() E ′′ Equation f(x) = 0: solve(f, x) Python print: print python() Solve the differential equation f (x) + 9f(x) = 1: System of equations: solve([f, g], [x, y]) Pretty print: pprint() dsolve(f(x).diff(x, x) + 9*f(x) - 1, f(x)) Differential equation: dsolve(equation, f(x))

1