```python
from sympy import *
```


```python
init_printing(use_unicode=True)
```


```python
# A Matrix object is constructed by providing a list 
# of row vectors that make up the matrix
```


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


```python
print(A)
```

    Matrix([[1], [2], [3]])



```python
# For pretty printing
A
```


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


```python
AA
```


```python
print(AA)
```

    Matrix([[1, 2], [3, 4]])



```python
## Matrix transpose
B = AA.T
```


```python
B
```


```python
# Matrix multiplication
M = Matrix([[1,2,3],[4,5,6]])
```


```python
M
```


```python
N = M.T
```


```python
N
```


```python
MN = M*N
```


```python
MN
```


```python
# shape of the metrix. Number of rows and columns.
M.shape
```


```python
MN.shape
```


```python
# accessing entries
M = Matrix([[1,2,3],[4,5,6]])
```


```python
M
```


```python
M.row(0)
```


```python
M.col(1)
```


```python
# last column
M.col(-1)
```


```python
M[:,1]
```


```python
M[0,:]
```


```python
# insert row/col after a particular row/col
M = M.row_insert(1,Matrix([[0,4,9]]))
```


```python
M
```


```python
N = 2*M
```


```python
N
```


```python
N**2
```


```python
N**-1
```


```python
NNinv = N.inv()
```


```python
NNinv
```


```python
# determinant of a matrix
Ndet = N.det()
```


```python
Ndet
```


```python
NNinv.det()
```


```python
# matrix constructors
I = eye(4)
```


```python
I
```


```python
Z = zeros(3,4)
```


```python
Z
```


```python
ones(2,3)
```


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


```python
A.eigenvals()
```


```python
A.eigenvects()
```


```python
# diagonalisation A = P*D*Pinv
P, D = A.diagonalize()
```


```python
D
```


```python
P
```


```python
P*D*P**-1 == A
```




    True




```python
# characteristic polynomials
lamda = symbols('lamda')
```


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


```python
p
```


```python
factor(p)
```


```python

```

772a6bc44cf940ac85298c2f4b2949f9646b37e1
ipynb
Jupyter Notebook
5-matrices.ipynb
chennachaos/SA2CTechChatSymPy
9f1dbb48655ff5f8bdd6b4ced48b58aed0ba5bf4
MIT
5-matrices.ipynb
chennachaos/SA2CTechChatSymPy
9f1dbb48655ff5f8bdd6b4ced48b58aed0ba5bf4
MIT
5-matrices.ipynb
chennachaos/SA2CTechChatSymPy
9f1dbb48655ff5f8bdd6b4ced48b58aed0ba5bf4
MIT
Qwen/Qwen-72B
1. YES
2. YES