Part I¶
Find x and y that satisfies these two equations (AoPS Introduction to Algebra, problem 5.3):
$$x+3y=4$$$$-2x+5y=-30$$from sympy import *
x, y = symbols('x y')
# NOTE: the solve command needs the equations to be homogeneous (zero on the right-hand side.)
solve([x+3*y-4,-2*x+5*y+30],[x,y])
Part II¶
A problem from the 2011 Mathcounts competition
The eighth grade at Memorial Middle School is selling wrapping paper and gift bags to raise money for a field trip. They sold one-half as many rolls of wrapping paper as they did gift bags. The profit they make for each roll of wrapping paper is \$2.50 and for each gift bag is \$1.50. If the total profit was \$704, how many gift bags were sold?
from sympy import *
W, G = symbols('W G')
solve([2.50*W+1.50*G-704,G-2*W])
As an experiment, see what happens if you represent 2.50 as Fraction(5,2) and 1.50 as Fraction(3,2)
from fractions import Fraction
W, G = symbols('W G')
solve([Fraction(3,2)*W+Fraction(3,1)*G-1704,W-2*G])
Part III¶
Find coefficients a,b,c,d,e,f such that the following equation is balanced.
$ \textbf{a } CaSO_4 + \textbf{b } CH_4 + \textbf{c } CO_2 \rightarrow \textbf{d } CaCO_3 + \textbf{e } S + \textbf{f } H_2O $
For each element, write out an equation for the relevant coefficients so that the number of atoms of that element will be equal on both sides of the reaction.
Ca: a=d
S : a=e
O : 4a+2c=3d+f
C : b+c=d
H : 4b=2f
from sympy import *
a, b, c, d, e, f = symbols('a b c d e f')
solve([
a-d,
a-e,
4*a+2*c-3*d-f,
b+c-d,
4*b-2*f,
],[a,b,c,d,e,f])
Select a value for f that results in integer coefficients, and re-solve.
solve([
a-d,
a-e,
4*a+2*c-3*d-f,
b+c-d,
4*b-2*f,
f-6
],[a,b,c,d,e,f])