```python
import numpy as np
from sympy import *
from sympy.calculus.util import continuous_domain
import pandas as pd
import copy
from P1 import *


init_printing(use_unicode=True)



# a.B

# matrix  = Matrix([
#     [8.8,-1.3,-6.8, -36.4],
#     [9.7, 4.5, 5.6, 108],
#     [7.5,-0.5,-0.8,9.06],
# ])

matrix = Matrix([
[7.40, 6.00, 0.700, -42.1],
[-6.70, -5.20, 5.60, 22.2],
[-2.70, -1.40, 7.40, -6.47],
])


# matrix = Matrix([
# [5.10, 3.20, -7.3, -136 ],
# [-8.40, -5.20, 8.10, 186],
# [4, 7.10, 0.4, -74]
# ])
# matrix = Matrix([[0.600, -9.90, -2.20, -47.2], [-3.70, -0.500, 1.80, -1.96], [4.4,8.10,1.8, 20.5]])



# pprint(escalona_gauss(matrix, 3, True)[0])
a = gauss_elimi(matrix, 3, True, 0.001)
#a.recursi()





# vec = Matrix([-9.390888310, -5.671787784, 9.583116262])
# vec = Matrix([-3.51584937, 1.021725838, 0.4840877769])
vec = Matrix([-1.788673724, -4.532451158, -2.384439280])
# # for x in a.xs:
# #     pprint(x-vec)
abs(a.xs[0] - vec)
```

    
    
    Interacao  0
    Antes da iteracao
    ⎡7.4   6.0   0.7  -42.1⎤
    ⎢                      ⎥
    ⎢-6.7  -5.2  5.6  22.2 ⎥
    ⎢                      ⎥
    ⎣-2.7  -1.4  7.4  -6.47⎦
    Depois da iteracao
    matriz
    ⎡7.4  6.0   0.7   -42.1⎤
    ⎢                      ⎥
    ⎢ 0   0.23  6.23  -15.9⎥
    ⎢                      ⎥
    ⎣ 0   0.79  7.66  -21.9⎦
    []
    multiplicadores
    ⎡  0     0  0  0⎤
    ⎢               ⎥
    ⎢-0.905  0  0  0⎥
    ⎢               ⎥
    ⎣-0.365  0  0  0⎦
    
    
    Interacao  1
    Antes da iteracao
    ⎡7.4  6.0   0.7   -42.1⎤
    ⎢                      ⎥
    ⎢ 0   0.23  6.23  -15.9⎥
    ⎢                      ⎥
    ⎣ 0   0.79  7.66  -21.9⎦
    Depois da iteracao
    matriz
    ⎡7.4  6.0   0.7   -42.1⎤
    ⎢                      ⎥
    ⎢ 0   0.79  7.66  -21.9⎥
    ⎢                      ⎥
    ⎣ 0    0    4.0   -9.53⎦
    [(1, 2, 'Col 1')]
    multiplicadores
    ⎡  0       0    0  0⎤
    ⎢                   ⎥
    ⎢-0.365    0    0  0⎥
    ⎢                   ⎥
    ⎣-0.905  0.291  0  0⎦
    
    
    Interacao  2
    Antes da iteracao
    ⎡7.4  6.0   0.7   -42.1⎤
    ⎢                      ⎥
    ⎢ 0   0.79  7.66  -21.9⎥
    ⎢                      ⎥
    ⎣ 0    0    4.0   -9.53⎦
    Depois da iteracao
    matriz
    ⎡7.4  6.0   0.7   -42.1⎤
    ⎢                      ⎥
    ⎢ 0   0.79  7.66  -21.9⎥
    ⎢                      ⎥
    ⎣ 0    0    4.0   -9.53⎦
    [(1, 2, 'Col 1')]
    multiplicadores
    ⎡  0       0    0  0⎤
    ⎢                   ⎥
    ⎢-0.365    0    0  0⎥
    ⎢                   ⎥
    ⎣-0.905  0.291  0  0⎦





$\displaystyle \left[\begin{matrix}0.128673724\\0.147548842\\0.00443928000000016\end{matrix}\right]$




```python

max(abs(a.xs[0] - vec))
```


```python
a.xs[0]

```




$\displaystyle \left[\begin{matrix}-1.66\\-4.68\\-2.38\end{matrix}\right]$




```python
A = Matrix([
    [-0.3, -0.3, 6.5, 21.3],
    [3.6, 3.4, -1.6, -10.7],
    [7.8, -1, 1.5, -16.6]
])

Real = Matrix([-2.601908433, 1.117749365, 3.208423428])

a = gauss_elimi(A, 3, True, 0.1)
a.recursi()


print(max(abs(a.xs[0] - Real)))
```

    achou em 1 iteracoes
    0.00225063500000000



```python
# A = Matrix([
#     [-4, 9, -9, -6],
#     [1, 3, 8, -6],
#     [10, -8, 3, -5]
# ])

# A = Matrix([
# [6, -11, 5, -3],
# [-2, 7, -10, 10],
# [12, -2, -10, 7]
# ])
#
#
#
#
# erro = 0.00100
# var = 13.8
# Ms = []
#
# Aswa = (0,1)
# Bswa = (0,2)
# Cswa = (1,2)
#
# swaps = [Aswa, Bswa, Cswa]
#
# matrizes = []
# pes = []
#
# Perm = eye(3)
#
# def swap_recursi(iter, matriz, perm):
#
#     iter -= 1
#     row = copy.deepcopy(matriz)
#     col = copy.deepcopy(matriz)
#     perm = copy.deepcopy(perm)
#     counter = 0
#
#     for swap in swaps:
#         counter += 1
#         i = swap[0]
#         j = swap[1]
#         row_edit = copy.deepcopy(row)
#         row_edit.row_swap(i,j)
#         perm_edit = copy.deepcopy(perm)
#         perm_edit.row_swap(i,j)
#         matrizes.append(row_edit)
#         pes.append(perm_edit)
#         if iter > 0:
#             swap_recursi(iter,row_edit, perm_edit)
#
#     for swap in swaps:
#         counter += 1
#         i = swap[0]
#         j = swap[1]
#         col_edit = copy.deepcopy(col)
#         col_edit.col_swap(i,j)
#
#         perm_edit = copy.deepcopy(perm)
#         perm_edit.col_swap(i,j)
#
#         matrizes.append(col_edit)
#         pes.append(perm_edit)
#         if iter > 0:
#             swap_recursi(iter,col_edit, perm_edit)
#
#
#
# swap_recursi(4,A,Perm)
#
#
# for matrix in matrizes:
#     a = gauss_seidel(matrix, None, 0, None)
#     Ms.append(a.M)
#
# Ms.sort()
#
# M = min(Ms)
#
#
# print(M)
# last = 100000
# for i in range(0, 500):
#     print(i, M**i/(1-M) * var - erro)





```


```python

```


```python
# x = symbols('x')
# g0 = x*0 + 1
# g1 = x
# g2 = x**2
#
# GS = [g0, g1, g2]
# intervalo = Interval(2,9)
#
# Func = 10/9 + cbrt(2/7*x - 11/7)
#
# a = MMQ_conti(GS,x,Func,intervalo)
#
#

```
