SymPy Library Notes
SymPy Library Notes
What is SymPy?
• - A Python library for symbolic mathematics
• - Written entirely in Python
• - Capable of performing algebra, calculus,
discrete math, etc.
Why Use SymPy?
• - Automates algebraic operations
• - Supports code generation (e.g., in C, Fortran)
• - Useful for teaching, research, and computer
algebra systems
Core Features
• - Symbolic computation
• - Simplification
• - Solving equations
• - Calculus (differentiation/integration)
• - Series, matrices, logic
Getting Started with SymPy
• ```python
• from sympy import *
• x, y = symbols('x y')
• ```
• - `symbols()` creates symbolic variables
• - Use Python shell or Jupyter notebook
Basic Operations
• ```python
• expr = x**2 + 2*x + 1
• expand(expr)
• factor(expr)
• ```
• - `expand()` multiplies out
• - `factor()` simplifies into factors
Solving Equations
• ```python
• solve(x**2 - 4, x)
• ```
• - Returns: `[-2, 2]`
• - Can solve systems of equations too
Differentiation & Integration
• ```python
• diff(sin(x), x)
• integrate(exp(x), x)
• ```
• - `diff()` for differentiation
• - `integrate()` for definite/indefinite integrals
Matrix Operations
• ```python
• M = Matrix([[1, 2], [3, 4]])
• M.inv()
• ```
• - Matrix creation, inversion, determinant
Plotting (Optional)
• ```python
• plot(sin(x), (x, -10, 10))
• ```
• - For simple 2D plots using SymPy's plot
module
Code Generation & Applications
• - Generate C/Fortran code using
`sympy.utilities.codegen`
• - Use in math-based simulations, teaching,
symbolic logic
Summary
• - Easy to use symbolic math library
• - Great for math automation and learning
• - Scales from simple to complex applications
References
• - https://docs.sympy.org
• - SymPy GitHub Repository
• - Python official documentation