# Examples for use of `Eq`


```python
from symbolic_equation import Eq
```

## Solving a simple system of equations

https://pythonforundergradengineers.com/sympy-expressions-and-equations.html#Defining-Equations-in-Sympy


```python
from sympy import symbols
```


```python
x, y = symbols('x y')
```


```python
eq1 = Eq(2*x - y - 1, tag='I')
eq1
```




\begin{equation}
  2 x - y - 1 = 0
\tag{I}\end{equation}





```python
eq2 = Eq(x + y - 5, tag='II')
eq2
```




\begin{equation}
  x + y - 5 = 0
\tag{II}\end{equation}





```python
eq_y = (
    (eq1 - 2 * eq2).tag("I - 2 II")
    .transform(lambda eq: eq - 9)
    .transform(lambda eq: eq / (-3)).tag('y')
)
eq_y
```




\begin{align}
  9 - 3 y &= 0\tag{I - 2 II}\\
  - 3 y &= -9\\
  y &= 3
\tag{y}\end{align}





```python
eq_x = (
    eq1.apply_to_lhs('subs', eq_y.as_dict).reset().tag(r'$y$ in I')
    .transform(lambda eq: eq / 2)
    .transform(lambda eq: eq + 2).tag('x')
)
eq_x
```




\begin{align}
  2 x - 4 &= 0\tag{$y$ in I}\\
  x - 2 &= 0\\
  x &= 2
\tag{x}\end{align}




Alternatively, we could let `sympy` solve the equation directly:


```python
from sympy import solve
```


```python
sol = solve((eq1, eq2),(x, y))
```


```python
sol
```




    {x: 2, y: 3}



## Proof of Euler's equation (to 6th order)

https://austinrochford.com/posts/2014-02-05-eulers-formula-sympy.html


```python
from sympy import exp, sin, cos, I
```


```python
θ = symbols('theta', real=True)
```


```python
n = 6
```


```python
eq_euler = (
    Eq(exp(I * θ), cos(θ) + I * sin(θ))
    .apply('subs', {cos(θ): cos(θ).series(n=n)})
    .apply('subs', {sin(θ): sin(θ).series(n=n)})
    .apply_to_rhs('expand').amend(previous_lines=2)
    .apply_to_lhs('series', n=n)
)
eq_euler
```




\begin{align}
  e^{i \theta} &= i \sin{\left(\theta \right)} + \cos{\left(\theta \right)}\\
   &= 1 + i \theta - \frac{\theta^{2}}{2} - \frac{i \theta^{3}}{6} + \frac{\theta^{4}}{24} + \frac{i \theta^{5}}{120} + O\left(\theta^{6}\right)\\
  1 + i \theta - \frac{\theta^{2}}{2} - \frac{i \theta^{3}}{6} + \frac{\theta^{4}}{24} + \frac{i \theta^{5}}{120} + O\left(\theta^{6}\right) &= 1 + i \theta - \frac{\theta^{2}}{2} - \frac{i \theta^{3}}{6} + \frac{\theta^{4}}{24} + \frac{i \theta^{5}}{120} + O\left(\theta^{6}\right)
\end{align}





```python
eq_euler.lhs - eq_euler.rhs
```




$\displaystyle O\left(\theta^{6}\right)$



ede0ddc332bea568c671b8dca0af675b30f8811d
ipynb
Jupyter Notebook
examples.ipynb
goerz/symbolic_equation
b0677b216a220adba65a0b2dc14f27cd206a998f
BSD-3-Clause
2019-12-10T15:45:53.000Z
2019-12-10T15:45:53.000Z
examples.ipynb
goerz/symbolic_equation
b0677b216a220adba65a0b2dc14f27cd206a998f
BSD-3-Clause
examples.ipynb
goerz/symbolic_equation
b0677b216a220adba65a0b2dc14f27cd206a998f
BSD-3-Clause
Qwen/Qwen-72B
1. YES
2. YES