# Linear-Equations.ipynb

In [1]:
from _linearEq import LinearEquations
from sympy import Eq, symbols
# %matplotlib notebook

In [2]:
x, y, z = symbols('x y z')
eq1 = Eq(- y + 2*z, -6)
eq2 = Eq(3*x + 6*y -8*z, 1)
eq3 = Eq(-4*x + 5*y + 5*z, 1)
display(eq1, eq2, eq3)

$\displaystyle - y + 2 z = -6$
$\displaystyle 3 x + 6 y - 8 z = 1$
$\displaystyle - 4 x + 5 y + 5 z = 1$
In [3]:
le = LinearEquations(eq1, eq2, eq3, var = [x, y, z])
le.displayEqs()

$\displaystyle - y + 2 z = -6$
$\displaystyle 3 x + 6 y - 8 z = 1$
$\displaystyle - 4 x + 5 y + 5 z = 1$

### Solve equations

In [4]:
le.solve()

Out[4]:
{x: -409/61, y: -88/61, z: -227/61}

### Plot equations

#### Plot basis vectors

In [5]:
le.displayEqs()

$\displaystyle - y + 2 z = -6$
$\displaystyle 3 x + 6 y - 8 z = 1$
$\displaystyle - 4 x + 5 y + 5 z = 1$
In [6]:
le.plot(plotType = 'Basis')


#### Plot the equations

In [7]:
le.plot()

In [8]:
le.plot('coln')


## Solve equations

In [9]:
le.solution()

$\displaystyle - y + 2 z = -6$
$\displaystyle 3 x + 6 y - 8 z = 1$
$\displaystyle - 4 x + 5 y + 5 z = 1$
Converting the equations into matrices.

$\displaystyle A X = B$
Expanding the matrices.

$\displaystyle \left[\begin{matrix}0 & -1 & 2\\3 & 6 & -8\\-4 & 5 & 5\end{matrix}\right] \left[\begin{matrix}x\\y\\z\end{matrix}\right] = \left[\begin{matrix}-6\\1\\1\end{matrix}\right]$
Multiplying A**-1 on both the sides.

$\displaystyle A^{-1} A X = A^{-1} B$
$\displaystyle \left[\begin{matrix}\frac{70}{61} & \frac{15}{61} & - \frac{4}{61}\\\frac{17}{61} & \frac{8}{61} & \frac{6}{61}\\\frac{39}{61} & \frac{4}{61} & \frac{3}{61}\end{matrix}\right] \left[\begin{matrix}0 & -1 & 2\\3 & 6 & -8\\-4 & 5 & 5\end{matrix}\right] \left[\begin{matrix}x\\y\\z\end{matrix}\right] = \left[\begin{matrix}\frac{70}{61} & \frac{15}{61} & - \frac{4}{61}\\\frac{17}{61} & \frac{8}{61} & \frac{6}{61}\\\frac{39}{61} & \frac{4}{61} & \frac{3}{61}\end{matrix}\right] \left[\begin{matrix}-6\\1\\1\end{matrix}\right]$
Canceling A**-1 and A.

$\displaystyle X = A^{-1} B$
$\displaystyle \left[\begin{matrix}x\\y\\z\end{matrix}\right] = \left[\begin{matrix}- \frac{409}{61}\\- \frac{88}{61}\\- \frac{227}{61}\end{matrix}\right]$
These are the values for the variables

$\displaystyle x = - \frac{409}{61}$
$\displaystyle y = - \frac{88}{61}$
$\displaystyle z = - \frac{227}{61}$

## 2D equations

In [10]:
x, y, z = symbols('x y z')
eq1 = Eq(x - y, -6)
eq2 = Eq(3*x + 5*y, 12)

In [11]:
le = LinearEquations(eq1, eq2, var = [x, y])
le.displayEqs()

$\displaystyle x - y = -6$
$\displaystyle 3 x + 5 y = 12$
In [12]:
le.solve()

Out[12]:
{x: -9/4, y: 15/4}
In [13]:
le.plot(plotType = 'Basis')

In [14]:
le.plot()

In [15]:
le.plot('coln')

In [16]:
le.solution()

$\displaystyle x - y = -6$
$\displaystyle 3 x + 5 y = 12$
Converting the equations into matrices.

$\displaystyle A X = B$
Expanding the matrices.

$\displaystyle \left[\begin{matrix}1 & -1\\3 & 5\end{matrix}\right] \left[\begin{matrix}x\\y\end{matrix}\right] = \left[\begin{matrix}-6\\12\end{matrix}\right]$
Multiplying A**-1 on both the sides.

$\displaystyle A^{-1} A X = A^{-1} B$
$\displaystyle \left[\begin{matrix}\frac{5}{8} & \frac{1}{8}\\- \frac{3}{8} & \frac{1}{8}\end{matrix}\right] \left[\begin{matrix}1 & -1\\3 & 5\end{matrix}\right] \left[\begin{matrix}x\\y\end{matrix}\right] = \left[\begin{matrix}\frac{5}{8} & \frac{1}{8}\\- \frac{3}{8} & \frac{1}{8}\end{matrix}\right] \left[\begin{matrix}-6\\12\end{matrix}\right]$
Canceling A**-1 and A.

$\displaystyle X = A^{-1} B$
$\displaystyle \left[\begin{matrix}x\\y\end{matrix}\right] = \left[\begin{matrix}- \frac{9}{4}\\\frac{15}{4}\end{matrix}\right]$
These are the values for the variables

$\displaystyle x = - \frac{9}{4}$
$\displaystyle y = \frac{15}{4}$
In [ ]:


In [ ]: