# SymPy Tutorial

*Arthur Ryman* <br/>
*Last Updated: 2020-04-16*


This notebook contains the examples from the 
[SymPy Tutorial](https://docs.sympy.org/latest/tutorial/index.html).

## Solvers


```python
from sympy import *
x, y, z = symbols('x y z')
init_printing(use_unicode=True)
```

### A Note about Equations


```python
Eq(x, y)
```


```python
solveset(Eq(x**2, 1), x)
```


```python
solveset(Eq(x**2 - 1, 0), x)
```


```python
solveset(x**2 - 1, x)
```

### Solving Equations Algebraically


```python
solveset(x**2 - x, x)
```


```python
solveset(x - x, x, domain=S.Reals)
```


```python
solveset(sin(x) - 1, x, domain=S.Reals)
```


```python
solveset(exp(x), x)
```


```python
solveset(cos(x) - x, x)
```


```python
linsolve([x + y + z - 1, x + y + 2*z - 3], (x, y, z))
```


```python
linsolve(Matrix(([1, 1, 1, 1], [1, 1, 2, 3])), (x,y,z))
```


```python
M = Matrix(((1, 1, 1, 1), (1, 1, 2, 3)))
system = A, b = M[:, :-1], M[:, -1]
linsolve(system, x, y, z)
```


```python
a, b, c, d = symbols('a, b, c, d', real=True)
nonlinsolve([a**2 + a, a - b], [a, b])
```


```python
nonlinsolve([x*y - 1, x - 2], x, y)
```


```python
nonlinsolve([x**2 + 1, y**2 + 1], [x, y])
```


```python
from sympy import sqrt
system = [x**2 - 2*y**2 - 2, x*y - 2]
vars = [x, y]
nonlinsolve(system, vars)
```


```python
system = [exp(x) - sin(y), 1/y - 3]
nonlinsolve(system, vars)
```


```python
nonlinsolve([x*y, x*y - x], [x, y])
```


```python
system = [a**2 + a*c, a - b]
nonlinsolve(system, [a, b])
```


```python
solve([x**2 - y**2/exp(x)], [x, y], dict=True)
```


```python
solve([sin(x + y), cos(x - y)], [x, y])
```


```python
solveset(x**3 - 6*x**2  + 9*x, x)
```


```python
roots(x**3 - 6*x**2 + 9*x, x)
```


```python
solve(x*exp(x) - 1, x)
```

### Solving Differential Equations


```python
f, g = symbols('f g', cls=Function)
```


```python
f(x)
```


```python
f(x).diff(x)
```


```python
diffeq = Eq(f(x).diff(x, x) - 2*f(x).diff(x) + f(x), sin(x))
diffeq
```


```python
dsolve(diffeq, f(x))
```


```python
dsolve(f(x).diff(x)*(1 - sin(f(x))) - 1, f(x))
```

a58317d1c6db070e3bb897126c19f9329945df3b
ipynb
Jupyter Notebook
notes/docs.sympy.org/tutorial/solvers.ipynb
agryman/acmpy
9566a0abce51cb610ec6c79eaea2e2b26b707419
MIT
notes/docs.sympy.org/tutorial/solvers.ipynb
agryman/acmpy
9566a0abce51cb610ec6c79eaea2e2b26b707419
MIT
2022-01-21T22:17:28.000Z
2022-01-21T22:17:28.000Z
notes/docs.sympy.org/tutorial/solvers.ipynb
agryman/acmpy
9566a0abce51cb610ec6c79eaea2e2b26b707419
MIT
Qwen/Qwen-72B
1. YES
2. YES