```python
%matplotlib inline
```


```python
import numpy as np
import numpy.polynomial.polynomial as p

import matplotlib.pyplot as plt

import sympy
```

# Basic Algebra
### Lecture Demos


```python
p.polyadd([-8,5,2], [-2,0,0,0,3])
result = p.polymul([-8,5,2], [-2,0,0,0,3])
```


```python
list(reversed(result))
```




    [6.0, 15.0, -24.0, 0.0, -4.0, -10.0, 16.0]




```python
for i in range(len(result)):
    print(i)
```

    0
    1
    2
    3
    4
    5
    6



```python
for i in range(len(result) -1, -1, -1):
    print(result[i],'*x^', str(i), end="+" )
```

    6.0 *x^ 6+15.0 *x^ 5+-24.0 *x^ 4+0.0 *x^ 3+-4.0 *x^ 2+-10.0 *x^ 1+16.0 *x^ 0+


```python
result_for_printtin = list(reversed(result))
result_for_printtin
```




    [6.0, 15.0, -24.0, 0.0, -4.0, -10.0, 16.0]




```python
sympy.init_printing()
x = sympy.symbols("x")
```


```python
sympy.Poly(result_for_printtin, x)
## every time polynoms from numpy have to be reversed because simpy expext polonoms to be from higher to lower power
```


```python
sympy.Poly(result, x)
## this is wron g since it is not reveresed 
```


```python
## Sets declaration
positive_x = {x for x in range(-5, 5) if x>=0}
positive_x
##{−5,−4,−3,−2,−1,0,1,2,3,4} without x>=0
list(positive_x)[4:0:-1]
## [0, 1, 2, 3, 4, −1, −5, −4, −3, −2]  without x>=0
```

### List and setd differences


```python
type([x for x in range(-5, 6)])
```




    list




```python
type({x for x in range(-5, 6)})
```




    set




```python
[x**2 for x in range(-5, 6)]
```


```python
{x**2 for x in range(-5, 6)}
```


```python
set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6, 7, 8, 9, 3, 4}
print(len(set2))
print(1 in set2)
print(10 not in set1)
print({1,2}.issubset(set1))
print(set1.union(set2))
print(set2.difference(set1))
print(set1.symmetric_difference(set2))
```

    7
    False
    True
    True
    {1, 2, 3, 4, 5, 6, 7, 8, 9}
    {5, 6, 7, 8, 9}
    {1, 2, 5, 6, 7, 8, 9}


### Functions


```python
def sum_two_numbers(a, b):
    return a+b
```


```python
sum_two_numbers(sum_two_numbers(sum_two_numbers(89, 56),90),78)
```


```python
x = np.linspace(-2*np.pi, 2*np.pi, 5000)
```


```python
y = np.sin(x)
y_1 =np.cos(x)
plt.plot(x, y, label = "sin(x)")
plt.plot(x, y_1, label = "cos(x)")
plt.legend()
plt.show()
```


```python
def plot_math_functions(functions, x_min, x_max, num_point):
    x = np.linspace(x_min,x_max, num_point)
    for f in functions:
        y = f(x)    
        plt.plot(x, y)
    #plt.gca().set_aspect("equal")
    plt.show()
```


```python
plot_math_functions([np.sin, np.cos, lambda x: 2*x -4], -2*np.pi, 2*np.pi, 5000)
```


```python
plot_math_functions([lambda x: x**2, lambda x: 3*x +10], -10,10, 500)
```

#### draw cyrcle


```python
plot_math_functions ([lambda x:np.sqrt(1-x**2), lambda x: -np.sqrt(1-x**2)], -1, 1, 2000)
```

#### polar coord sys


```python
phi = np.linspace(0,2*np.pi, 5000)
r = [1]*5000
plt.polar(phi, r)
```

### Complex numbers



```python
3j * 3j
```




    (-9+0j)




```python
x= 1j*1j
print(type(x))
print(x.real)
print(x.imag)
print(x)
```

    <class 'complex'>
    -1.0
    0.0
    (-1+0j)



```python
print((3 +3j) *(2-7j)*(-3+2j))
```

    (-51+99j)



```python
import cmath
def solve_quadratic_equations(a, b, c):
    discriminant = cmath.sqrt(b**2 -4*a*c)
    return [(-b+discriminant)/(2*a),(-b-discriminant)/(2*a) ]
```


```python
print(solve_quadratic_equations(1,-3,-4))
print(solve_quadratic_equations(1,4,5))
```

    [(4+0j), (-1+0j)]
    [(-2+1j), (-2-1j)]



```python

```

562b6dcf079837ddae891403bbb969e6cd02efd4
ipynb
Jupyter Notebook
MathConceptsForDevelopers/02.Basic-AlgebraLectuer/Basic Linear Algebra Lecture.ipynb
LuGeorgiev/Python-SoftUni
545daa4684b7a333f78dd958f8e9d13263575ddf
MIT
MathConceptsForDevelopers/02.Basic-AlgebraLectuer/Basic Linear Algebra Lecture.ipynb
LuGeorgiev/Python-SoftUni
545daa4684b7a333f78dd958f8e9d13263575ddf
MIT
MathConceptsForDevelopers/02.Basic-AlgebraLectuer/Basic Linear Algebra Lecture.ipynb
LuGeorgiev/Python-SoftUni
545daa4684b7a333f78dd958f8e9d13263575ddf
MIT
Qwen/Qwen-72B
1. YES
2. YES