Jupyter Snippet CB2nd 01_sympy_intro
Jupyter Snippet CB2nd 01_sympy_intro
15.1. Diving into symbolic computing with SymPy
from sympy import *
init_printing()
var('x y')
x, y = symbols('x y')
expr1 = (x + 1) ** 2
expr2 = x**2 + 2 * x + 1
expr1 == expr2
False
simplify(expr1 - expr2)
expr1.subs(x, expr1)
expr1.subs(x, pi)
expr1.subs(x, S(1) / 2)
_.evalf()
f = lambdify(x, expr1)
import numpy as np
f(np.linspace(-2., 2., 5))
array([ 1., 0., 1., 4., 9.])