### Solve Equations

* fit time-of-flight to mass spectrum

$ \text{time} = k \sqrt{\frac{\text{mass}}{\text{charge}}} + \text{offset}$

* numeric approx.:

$ \frac{\text{mass}}{\text{charge}} = (c_1 \text{time} + c_2 )^2 $


```python
import numpy as np
import matplotlib.pyplot as plt

from sympy.solvers import solve
from sympy import symbols, Eq


```


```python
m1, tof1 = 198, 13.0184     
m2, tof2 = 71, 8.18377 
```


```python
c1, c2 = symbols('c1,c2')

eq1 = Eq(m1,(c1*tof1+c2)**2)
eq2 = Eq(m2,(c1*tof2+c2)**2)

solutions = solve((eq1 , eq2) ,c1,c2)
         
solutions
```




    [(-4.65338548195968, 46.5083862788736),
     (-1.16763795911868, 1.12953072752030),
     (1.16763795911868, -1.12953072752030),
     (4.65338548195968, -46.5083862788736)]




```python
c1, c2 = [each for each in solutions if abs(each[0]) > abs(each[1])][0]

x = np.arange(start= 0, stop=200, step=1)
y = (c1 * x + c2)**2

plt.plot(x,y)
```


```python

```

0212cb50e90a839c4e969b6d9b698ec758d7c944
ipynb
Jupyter Notebook
solve_eq_sympy.ipynb
summiee/jupyter_demos
5a0c6c802a29d74cfda14fb4412b9df4aaebdfcf
MIT
solve_eq_sympy.ipynb
summiee/jupyter_demos
5a0c6c802a29d74cfda14fb4412b9df4aaebdfcf
MIT
solve_eq_sympy.ipynb
summiee/jupyter_demos
5a0c6c802a29d74cfda14fb4412b9df4aaebdfcf
MIT
2021-01-26T17:41:00.000Z
2021-01-26T17:41:00.000Z
Qwen/Qwen-72B
1. YES
2. YES