Block 85: SymPy: Symbolic Mathematics
Define and manipulate mathematical symbols and expressions.
Concepts
- from sympy import symbols, expand, factor, simplify
- Symbolic expression creation
- expand(), factor(), simplify()
- subs() for substitution
Code Examples
See exercise below.
Exercise
Define x and y as symbols. Expand (x+y)^3. Factor x^2 - 5x + 6. Substitute x=2 into an expression and compare with numeric calculation.
Homework
What is the difference between symbolic computation and numerical computation? Give 2 examples of when each is preferred.