obscure_packages = ["sympy"]
for pkg in obscure_packages:
try:
__import__(pkg) # check if installed
except ImportError:
print(f":warning: {pkg} not found. Installing...")
!pip install {pkg}
__import__(pkg)
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from ipywidgets import interact
import ipywidgets as widgets
from sympy import Symbol, Eq, solve_undetermined_coeffs, apartPartial Fractions¶
This example was copied from Wikipedia.
For example, we want to decompose:
First, we factor:
So we have the PFD:
Giving us the polynomial identity: $$
$$
Which we can solve using SymPy:
A = Symbol('A')
B = Symbol('B')
x = Symbol('x')
solve_undetermined_coeffs(Eq(1, A * (x - 1) + B * (x + 3)), [A, B], x)Docs for solve_undteremined_coeffs
We can also have SymPy perform the entire PFD but this probably defeats the purpose:
apart(1 / (x**2 + 2*x - 3))question 1¶
C = Symbol('C')
solve_undetermined_coeffs(Eq(1, A * (x + 2) ** 2 + B * (x - 1) * (x + 2) + C * (x-1)), [A, B, C], x)question 3¶
D = Symbol('D')
E = Symbol('E')
solve_undetermined_coeffs(Eq(1, A * (x ** 2 + 2 * x + 5) ** 2 + (B * x + C) * (x - 1) * (x ** 2 + 2 * x + 5) + (D * x + E) * (x-1)), [A, B, C, D, E], x)