```python
import sympy as sm
import scipy as sp
```


```python
sm.init_printing()
```

### Calculate determinat


```python
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 \
= sm.symbols("m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44")
```


```python
A = sm.Matrix([[m11, m12, m13, m14], 
               [m21, m22, m23, m24], 
               [m31, m32, m33, m34],
               [m41, m42, m43, m44]])
```


```python
A.det()
```


```python
A_num = A.subs({m11:3, m12:7, m13:-2, m14:4, 
                m21:-3, m22:-2, m23:6, m24:-4, 
                m31:5, m32:5, m33:-3, m34:2, 
                m41:2, m42:6, m43:-5, m44:3})
A_num
```




$\displaystyle \left[\begin{matrix}3 & 7 & -2 & 4\\-3 & -2 & 6 & -4\\5 & 5 & -3 & 2\\2 & 6 & -5 & 3\end{matrix}\right]$




```python
A_num.det()
```

### Inverse matrix


```python
A_num.inv()
```




$\displaystyle \left[\begin{matrix}- \frac{8}{303} & - \frac{5}{101} & \frac{82}{303} & - \frac{64}{303}\\\frac{7}{303} & \frac{17}{101} & \frac{4}{303} & \frac{56}{303}\\\frac{67}{303} & \frac{4}{101} & - \frac{5}{303} & - \frac{70}{303}\\\frac{103}{303} & - \frac{24}{101} & - \frac{71}{303} & - \frac{85}{303}\end{matrix}\right]$



### Systems of equations


```python
x1, x2, x3, x4 = sm.symbols("x1, x2, x3, x4")
```


```python
sm.solve([x1 + 5*x2 + 4*x3 + 3*x4 - 1, 
         2*x1 - x2 + 2*x3 - x4, 
         5*x1 + 3*x2 + 8*x3 + x4 - 1], 
         [x1, x2, x3, x4])
```


```python
sm.solve([x1 + x2 - 2*x3 + x4 - 1, 
          x1 - 3*x2 + x3 + x4, 
          4*x1 - x2 - x3 - x4 - 1,
          4*x1 + 3*x2 - 4*x3 - x4 - 2], [x1, x2, x3, x4])
```

### Limits


```python
x, y, b, c = sm.symbols("x, y, b, c")
```


```python
f_1 = (1 - sm.cos(5*x))/(x**2)
```


```python
sm.limit(f_1, x, 0)
```


```python
f_2 = ((x+1)/(x+b))**(x+c)
```


```python
sm.limit(f_1, x, sm.oo)
```

### Derivatives


```python
a, b = sm.symbols("a, b")
```


```python
sm.diff ((sm.asin(x)/x)**(x**3), x)
```


```python
sm.diff ((sm.ln(sm.sqrt((a+sm.sin(x))/sm.tan(x)-b))), x)
```

### Mixed partial derivatives


```python
n = sm.Symbol("n")
```


```python
f1 = x**(2*n)*sm.sin(y)
```


```python
f2 = (sm.E**y)*sm.sin(n*x**2)
```


```python
sm.diff (f1, x, 2, y, 3)
```


```python
sm.diff (f2, x, 2, y, 3)
```

### Integrals


```python
r = sm.Symbol ("r")
```


```python
f = (sm.sin(sm.cbrt(x)))/sm.cbrt(x**2)
g = sm.sqrt(r**2 - x**2, x)
g
```


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


```python
sm.integrate (g, (x, 0, r))
```




$\displaystyle \begin{cases} - \int\limits_{r}^{0} \begin{cases} - \frac{i r}{\sqrt{-1 + \frac{x^{2}}{r^{2}}}} + \frac{3 i x^{2}}{2 r \sqrt{-1 + \frac{x^{2}}{r^{2}}}} + \frac{i x^{2}}{2 r \left(-1 + \frac{x^{2}}{r^{2}}\right)^{\frac{3}{2}}} - \frac{i x^{4}}{2 r^{3} \left(-1 + \frac{x^{2}}{r^{2}}\right)^{\frac{3}{2}}} & \text{for}\: \frac{\left|{x^{2}}\right|}{r^{2}} > 1 \\\frac{r \sqrt{1 - \frac{x^{2}}{r^{2}}}}{2} + \frac{r}{2 \sqrt{1 - \frac{x^{2}}{r^{2}}}} - \frac{x^{2}}{2 r \sqrt{1 - \frac{x^{2}}{r^{2}}}} & \text{otherwise} \end{cases}\, dx & \text{for}\: r < 0 \\\int\limits_{0}^{r} \begin{cases} - \frac{i r}{\sqrt{-1 + \frac{x^{2}}{r^{2}}}} + \frac{3 i x^{2}}{2 r \sqrt{-1 + \frac{x^{2}}{r^{2}}}} + \frac{i x^{2}}{2 r \left(-1 + \frac{x^{2}}{r^{2}}\right)^{\frac{3}{2}}} - \frac{i x^{4}}{2 r^{3} \left(-1 + \frac{x^{2}}{r^{2}}\right)^{\frac{3}{2}}} & \text{for}\: \frac{\left|{x^{2}}\right|}{r^{2}} > 1 \\\frac{r \sqrt{1 - \frac{x^{2}}{r^{2}}}}{2} + \frac{r}{2 \sqrt{1 - \frac{x^{2}}{r^{2}}}} - \frac{x^{2}}{2 r \sqrt{1 - \frac{x^{2}}{r^{2}}}} & \text{otherwise} \end{cases}\, dx & \text{otherwise} \end{cases}$



### Sum and product


```python
k = sm.Symbol("k")
```


```python
s = 1/((2*n - 1)*(2*n + 1))
```


```python
sm.Sum(s, (n, 1, sm.oo)).evalf()
```


```python
p = sm.sin(k)
```


```python
sm.Product(p, (k, 1, 100)).evalf()
```

### Graphs


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


```python
matplotlib.rcParams.update({'axes.facecolor': 'white', 
                            'axes.labelcolor': 'darkslategray', 
                            'axes.titlecolor': 'darkslategray', 
                            'text.color': 'darkslategray',
                            'font.size': '15', 
                            'figure.titleweight':'heavy',
                            'grid.linestyle': 'dashed',
                            'legend.fontsize': '15',
                            'legend.loc': 'lower left'})
```


```python
x = np.linspace(-2, 3, 1000)
f = -np.exp(-(x - 0.7)**2)
```


```python
fig, ax = plt.subplots()

ax.plot(x, f, label = r'${e^{-(x - 0.7)}}^2$')
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.legend()
ax.grid(True)
plt.title('First graph')
plt.show()
```


```python
x = np.linspace(-10, 10, 1000)
y = np.linspace(-10, 10, 1000)

z = np.sin(np.sqrt(x**2 + y**2))/np.sqrt(x**2 + y**2 + 0.1)
```


```python
fig, ax = plt.subplots()

ax.plot(x, z)
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.grid(True)
plt.title('Second graph')
plt.show()
```


```python
x = sm.Symbol("x")
f = -sm.exp(-(x - 0.7)**2)
f_diff = sm.diff(f, x)
x_min = sm.solve(f_diff, x)
```


```python
x = np.linspace(-10, 10, 1000)
y = -(1.4-2*x)*np.e**(-(x-0.7)**2)
```


```python
fig, ax = plt.subplots()

ax.plot(x, y)
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.grid(True)
plt.title('derivative')
plt.show()
```

As you can see on the graph, x_min is minimum of function


```python

```

6437dccd7180a1d2ad07d6d5bbd816f37636c000
ipynb
Jupyter Notebook
Homework #2.ipynb
e-katherina/USM_python
61389312d5ee3a33e5503837f0e92e3c0df425dd
MIT
2021-04-30T10:40:14.000Z
2021-08-31T06:38:32.000Z
Homework #2.ipynb
e-katherina/USM_python
61389312d5ee3a33e5503837f0e92e3c0df425dd
MIT
Homework #2.ipynb
e-katherina/USM_python
61389312d5ee3a33e5503837f0e92e3c0df425dd
MIT
Qwen/Qwen-72B
1. YES
2. YES