Experimenting with Equations¶
SymPy is a Python library for symbolic mathematics.
In Jupyter Notebook, we can initialize SymPy as follows.
from sympy import init_session
init_session()
IPython console for SymPy 1.12 (Python 3.11.5-64-bit) (ground types: python)
These commands were executed:
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
>>> init_printing()
Documentation can be found at https://docs.sympy.org/1.12/
Balancing Equations¶
In grade 9 students might be able to understand the mechanics of balancing an equation to isolate a variable but struggle with arithmetic or organizing their solution across multiple lines.
In these cases we might encourage students to demonstrate their understanding of balancing an equation by using a computer algebra system.
We might provide a notebook with a series of expressions defined, like this...
left = 2 * x + 6
left
right = 24
right
Try out ideas for simplifying¶
Now we might encourage students to experiment to solve: $$2x + 6 = 24$$
Perhaps adding $6$ to the left side might make the expression simpler?
left + 6
The student should hopefully realize that $2x + 12$ is a more complex expression than $2x + 6$... especially as our goal was to isolate the term with $x$.
They might realize subtracting six was the better approach...
left - 6
Now that the left side is simpler, we remind students we need to keep the equation balanced, so they should apply the same operation to the right side expression.
right - 6
This is progress, so we'll "save" these operations.
left = left - 6
left
right = right - 6
right
Continuing to experiment...
left / 2
right / 2
Save the operations...
left = left / 2
left
right = right / 2
right
Check their solution¶
Optionally, we can have students check their process of simplification using the computer algebra system.
First, they restore each side to the original expression.
left = 2 * x + 6
left
right = 24
right
Then they create the equation:
equation = Eq(left, right)
equation
Finally, they check their work above using the CAS:
solve(equation, x)
Multiple representations¶
We also might want to reinforce that expressions can be represented graphically, and that the solution to a single variable equation can be seen as the intersection of those graphs.
First we import the plotting library to create an inline graph:
%matplotlib inline
Then we plot both expressions on the same graph:
p = plot(left, right)
We observe that the intersection of the two graphs occurs when $x=9$.