```python
#
# SA2C Tech chat
# Topic: SymPy
# Date: 2020-04-14
#
```


```python
#  Outline
#------------------
#
#* Symbolic computation - what is it?
#*
#* Introduction to SymPy
#*
#* Advantages/disadvantages of SymPy
#*
#* Basics - introduction to symbols
#*
#* Printing - pretty printing
#*
#* Simplification of expressions
#*
#* Solvers - finding roots
#*
#* Basic Calculus - differentiation, integration, limits
#*
#* Matrices - basic operations, constructors, advanced methods
#*
#* Tensor Calculus
```


```python
import math
```


```python
math.sqrt(8)
```




    2.8284271247461903




```python
import sympy
```


```python
sympy.sqrt(8)
```




    2*sqrt(2)




```python
type(math.sqrt(8))
```




    float




```python
type(sympy.sqrt(8))
```




    sympy.core.mul.Mul




```python
x*(x+2)
```


```python
import sympy
```


```python
x = sympy.var('x')
```


```python
x*(x+2)
```




    x*(x + 2)




```python
from sympy import *
```


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


```python
f = x*x*y*z + t*x
```


```python
f
```




    t*x + x**2*y*z




```python
print(f)
```

    t*x + x**2*y*z



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


```python
x
```




    y




```python
expand(x*(x+2))
```




    y**2 + 2*y




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


```python
expand(x*(x+2))
```




    x**2 + 2*x




```python
factor(x**2+2*x)
```




    x*(x + 2)




```python
expr = x**2+2*x
```


```python
expr.subs(x,1)
```




    3




```python
init_printing()
```


```python
x**2+2*x
```


```python
Integral(sqrt(1/x),x)
```


```python
x,y,z = symbols('x y z', integer=True)
```


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


```python
type(f)
```




    sympy.core.function.UndefinedFunction




```python
type(x)
```




    sympy.core.symbol.Symbol




```python
# polynomials
f = (x**2-3*x+2)/(x**2-x)
```


```python
f
```


```python
simplify(f)
```


```python
f = x**2 - 3*x +2
```


```python
f
```


```python
solve(f,x)
```


```python
g = x**2 + x + 1
```


```python
g
```


```python
solve(g, x)
```


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


```python
g = x**2 + x + 1
```


```python
solve(g,x)
```


```python
y = solve(g,x)
```


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


```python
y = solve(g,x)
```


```python
y[0]
```


```python
y[1]
```


```python
y[0].evalf()
```


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


```python
eq1 = Eq(x+y+z, 0)
```


```python
eq2 = Eq(2*x+y-z,10)
```


```python
eq3 = Eq(y+2*z,5)
```


```python
solve([eq1, eq2, eq3], [x,y,z])
```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python
f = x**2
```


```python
diff(f,x)
```


```python
diff(f,x,1)
```


```python
diff(f,x,3)
```


```python
g = sin(x)*cos(y)*exp(z)
```


```python
g
```


```python
diff(g, z, 2)
```


```python
diff(g, x, 3)
```


```python
diff(g)
```


```python
diff(f,x)
```


```python
integrate(f,x)
```


```python
df = Derivative(f, x, z, t)
```


```python
df
```


```python
df.doit()
```


```python
limits(sin(x)/x, x, 0)
```


```python
from sympy import *
```


```python
limits(sin(x)/x, x, 0)
```


```python
limit(sin(x)/x, x, 0)
```


```python
f = exp(x)
```


```python
f
```


```python
f.series(x,0,4)
```


```python
f.series(x,0,4).removeO()
```


```python
f.series(x,2,4).removeO()
```


```python
# Matrices
```


```python
A = Matrix([1,2,3])
```


```python
A
```


```python
B = Matrix([[1,2,3],[4,5,6],[7,8,9]])
```


```python
B
```


```python
B.T
```


```python
C = 2*B
```


```python
C
```


```python
D = B+C
```


```python
D
```


```python
D.eigenvals()
```


```python
P, E = D.diagonalize()
```


```python
E
```


```python
P
```


```python
lamda = symbols('lamda')
```


```python
p = D.charpoly(lamda)
```


```python
p
```


```python
A = eye(4)
```


```python
print(A)
```

    Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])



```python

```

468cd35547bfe18a4c00bead856ccd50f944ba13
ipynb
Jupyter Notebook
TechChat.ipynb
chennachaos/SA2CTechChatSymPy
9f1dbb48655ff5f8bdd6b4ced48b58aed0ba5bf4
MIT
TechChat.ipynb
chennachaos/SA2CTechChatSymPy
9f1dbb48655ff5f8bdd6b4ced48b58aed0ba5bf4
MIT
TechChat.ipynb
chennachaos/SA2CTechChatSymPy
9f1dbb48655ff5f8bdd6b4ced48b58aed0ba5bf4
MIT
Qwen/Qwen-72B
1. YES
2. YES