Open this script in colab
https://colab.research.google.com/github/StatisticalMice/experiments/blob/master/p-misc/sympy-example.ipynb


```python
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="whitegrid")
```

Find equation for a line that goes through points (3,0) and (7,5)


```python
x, y, m, b = sp.symbols('x y m b')
```


```python
f = sp.Eq(y, m*x + b)
f
```




$\displaystyle y = b + m x$




```python
s = sp.solve([f.subs({x:3,y:0}), 
              f.subs({x:7,y:5})],
             (b,m))
s
```




    {b: -15/4, m: 5/4}




```python
f = f.subs(s)
f
```




$\displaystyle y = \frac{5 x}{4} - \frac{15}{4}$




```python
lf = sp.lambdify(x, f.rhs, 'numpy')
```


```python
x_vals = np.linspace(-10, 10, 200)
```


```python
y_vals = lf(x_vals)
```


```python
sns.lineplot(x_vals, y_vals)
plt.scatter(3, 0, marker='o', s=100)
plt.scatter(7, 5, marker='o', s=100)
```

Find equation for a line that has slope 3 and goes through point (-2,0)


```python
f = sp.Eq(y, m*x + b)
f
```




$\displaystyle y = b + m x$




```python
f = f.subs(m, 3)
f
```




$\displaystyle y = b + 3 x$




```python
s = sp.solve(f.subs({x:-2, y:0}), (b), dict=True)
s
```




    [{b: 6}]




```python
f = f.subs(s[0])
f
```




$\displaystyle y = 3 x + 6$




```python
lf = sp.lambdify(x, f.rhs, 'numpy')
```


```python
x_vals = np.linspace(-10, 10, 200)
```


```python
y_vals = lf(x_vals)
```


```python
sns.lineplot(x_vals, y_vals)
plt.scatter(-2, 0, marker='o', s=100)
```


```python

```


```python

```

9e664eb0bd9fb8ee95db53b40378dc1e85e44d19
ipynb
Jupyter Notebook
p-misc/sympy-example.ipynb
StatisticalMice/experiments
f1835aa46e1ec30594d562e40490745122dbd444
CC-BY-3.0 MIT
p-misc/sympy-example.ipynb
StatisticalMice/experiments
f1835aa46e1ec30594d562e40490745122dbd444
CC-BY-3.0 MIT
p-misc/sympy-example.ipynb
StatisticalMice/experiments
f1835aa46e1ec30594d562e40490745122dbd444
CC-BY-3.0 MIT
Qwen/Qwen-72B
1. YES
2. YES