Sympy Cheatsheet (
Total Page:16
File Type:pdf, Size:1020Kb
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: c = 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 Integers (Z): Integer(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: +=−: R/F or PgUp/PgDn or Numpad +/- Circle(Point(5,5), 3).is_tangent( 1: 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 p 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 jxj Natural logarithm: log(a) Calculate left-sided limit of the function x in 0: Gamma (Γ(x)): gamma(x) Factorial (n!): ( ) factorial(n) limit(abs(x)/x, x, 0, dir='-') Absolute value: abs(x) n BinomialP coefficient k : binomial(n, k) P b Calculate the sum 100 n2: Sum ( n=Qa expr): summation(expr, (n, a, b)) n=0 b summation(n**2, (n, 0, 100)) Calculus Product ( n=a expr): product(expr, (n, a, b)) P1 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]]) R 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) × R@x Identity matrix n n: eye(n) R 1 × Calculate the integral dx : R 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 series (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 00 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.