Scroll to Top

Virtual Math Learning Center

Virtual Math Learning Center Texas A&M University Virtual Math Learning Center

Creating and Manipulating Symbolic Expressions in Python

Author: David Manuel

In this video, it is shown how to create a symbolic expression in Python with a variable, and then how to factor, expand, and simplify the expression. It is also shown how to evaluate the expression by substituting a value for the variable.

Transcript 03

Problem: Simplify \(g(x)\) for \(g(x)=\dfrac{f(x)}{x^2-1}\) with \(f(x)=x^4+5x^3+8x^2+x-15\). Evaluate \(g(1)\) before and after simplifying \(g(x).\)

Python Code: 
from sympy import *

x=symbols('x')
f=x**4+5*x**3+8*x**2+x-15
print(f.factor())
f_factor=f.factor()
print(f_factor.expand())
g=f/(x**2-1)
print(g.simplify())
print(g.subs(x,1))
print(g.simplify().subs(x,1))

Open Python Notebook File

See more videos from this section