<jupyter_start><jupyter_text>APS 2 - Sistemas de equações (matrizes). Considerar epsilon_s = 0,0001%. Explicar como funcionam os comandos de inversão de matriz e multiplicação de matrizes usados pela linguagem de programação Python.<jupyter_code>import numpy as np
import math
import matplotlib.pyplot as plt
np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Exercício 12.23<jupyter_code>matrix = np.array([    [1,-1,-1,0],
                       [-35,0,-5,200],
                       [0,-27,5,0]
                       ])

matrix = matrix.astype('float64')<jupyter_output><empty_output><jupyter_text>Utilizando a eliminação de Gauss ingênua:<jupyter_code>temp = matrix[1][0]/matrix[0][0]
for i in range(4): 
    matrix[1][i] -= temp*matrix[0][i]
temp = matrix[2][1]/matrix[1][1]
for i in range(4): 
    matrix[2][i] -= temp*matrix[1][i]
print(matrix)<jupyter_output>[[1.000 -1.000 -1.000 0.000]
 [0.000 -35.000 -40.000 200.000]
 [0.000 0.000 35.857 -154.286]]<jupyter_text>i3:<jupyter_code>i3 = -154.286/35.857
print(i3)<jupyter_output>-4.302813955434085<jupyter_text>i2:<jupyter_code>i2 = (40*i3+200)/-35
print(i2)<jupyter_output>-0.7967840509324738<jupyter_text>i1:<jupyter_code>i1 = i2+i3
print(i1)<jupyter_output>-5.099598006366559<jupyter_text>O sinal negativo da corrente indica que ela tem sinal contrário ao que está no desenho acima.  Exercício 12.25utilizar eliminação de Gauss com pivotamento.   Matriz obtida a partir das leis de Kirchoff aplicadas ao circuito elétrico:<jupyter_code>matrix = np.array([  
    
    [-75,-25, 0,  0,-20, 0,-70],    
    [0  ,-25,-5,  0,  0, 0,  0],     
    [0  ,  0,-5,-10, 25, 0,  0],     
    [1  , -1, 0,  0,  0,-1,  0],    
    [1  ,  0, 0, -1, -1, 0,  0],    
    [0  ,  1, -1, 0, -1, 0,  0]    
                       ])

matrix = matrix.astype('float64')<jupyter_output><empty_output><jupyter_text>Matriz pivotada manualmente:<jupyter_code>matrix = np.array([  
    
    [-75,-25, 0,  0,-20, 0,-70], 
    [0  ,-25,-5,  0,  0, 0,  0],
    [0  ,  0,-5,-10, 25, 0,  0], 
    [1  ,  0, 0, -1, -1, 0,  0], 
    [0  ,  1, -1, 0, -1, 0,  0],
    [1  , -1, 0,  0,  0,-1,  0]       
                       ])

matrix = matrix.astype('float64')<jupyter_output><empty_output><jupyter_text>Primeiro coeficiente:<jupyter_code>temp = matrix[3][0]/matrix[0][0]
for i in range(7): 
    matrix[3][i] -= temp*matrix[0][i]

temp = matrix[5][0]/matrix[0][0]
for i in range(7): 
    matrix[5][i] -= temp*matrix[0][i]
print(matrix)<jupyter_output>[[-75.000 -25.000 0.000 0.000 -20.000 0.000 -70.000]
 [0.000 -25.000 -5.000 0.000 0.000 0.000 0.000]
 [0.000 0.000 -5.000 -10.000 25.000 0.000 0.000]
 [0.000 -0.333 0.000 -1.000 -1.267 0.000 -0.933]
 [0.000 1.000 -1.000 0.000 -1.000 0.000 0.000]
 [0.000 -1.333 0.000 0.000 -0.267 -1.000 -0.933]]<jupyter_text>Segundo coeficiente:<jupyter_code>temp = matrix[3][1]/matrix[1][1]
for i in range(7): 
    matrix[3][i] -= temp*matrix[1][i]

temp = matrix[4][1]/matrix[1][1]
for i in range(7): 
    matrix[4][i] -= temp*matrix[1][i]

temp = matrix[5][1]/matrix[1][1]
for i in range(7): 
    matrix[5][i] -= temp*matrix[1][i]
print(matrix)<jupyter_output>[[-75.000 -25.000 0.000 0.000 -20.000 0.000 -70.000]
 [0.000 -25.000 -5.000 0.000 0.000 0.000 0.000]
 [0.000 0.000 -5.000 -10.000 25.000 0.000 0.000]
 [0.000 0.000 0.067 -1.000 -1.267 0.000 -0.933]
 [0.000 0.000 -1.200 0.000 -1.000 0.000 0.000]
 [0.000 0.000 0.267 0.000 -0.267 -1.000 -0.933]]<jupyter_text>Terceiro coeficiente:<jupyter_code>temp = matrix[3][2]/matrix[2][2]
for i in range(6): 
    matrix[3][i] -= temp*matrix[2][i]

temp = matrix[4][2]/matrix[2][2]
for i in range(6): 
    matrix[4][i] -= temp*matrix[2][i]

temp = matrix[5][2]/matrix[2][2]
for i in range(6): 
    matrix[5][i] -= temp*matrix[2][i]
print(matrix)<jupyter_output>[[-75.000 -25.000 0.000 0.000 -20.000 0.000 -70.000]
 [0.000 -25.000 -5.000 0.000 0.000 0.000 0.000]
 [0.000 0.000 -5.000 -10.000 25.000 0.000 0.000]
 [0.000 0.000 0.000 -1.133 -0.933 0.000 -0.933]
 [0.000 0.000 0.000 2.400 -7.000 0.000 0.000]
 [0.000 0.000 0.000 -0.533 1.067 -1.000 -0.933]]<jupyter_text>Quarto coeficiente:<jupyter_code>temp = matrix[4][3]/matrix[3][3]
for i in range(7): 
    matrix[4][i] -= temp*matrix[3][i]
    
temp = matrix[5][3]/matrix[3][3]
for i in range(7): 
    matrix[5][i] -= temp*matrix[3][i]
print(matrix)<jupyter_output>[[-75.000 -25.000 0.000 0.000 -20.000 0.000 -70.000]
 [0.000 -25.000 -5.000 0.000 0.000 0.000 0.000]
 [0.000 0.000 -5.000 -10.000 25.000 0.000 0.000]
 [0.000 0.000 0.000 -1.133 -0.933 0.000 -0.933]
 [0.000 0.000 0.000 0.000 -8.976 0.000 -1.976]
 [0.000 0.000 0.000 0.000 1.506 -1.000 -0.494]]<jupyter_text>Quinto coeficiente:<jupyter_code>temp = matrix[5][4]/matrix[4][4]
for i in range(7): 
    matrix[5][i] -= temp*matrix[4][i]
print(matrix)<jupyter_output>[[-75.000 -25.000 0.000 0.000 -20.000 0.000 -70.000]
 [0.000 -25.000 -5.000 0.000 0.000 0.000 0.000]
 [0.000 0.000 -5.000 -10.000 25.000 0.000 0.000]
 [0.000 0.000 0.000 -1.133 -0.933 0.000 -0.933]
 [0.000 0.000 0.000 0.000 -8.976 0.000 -1.976]
 [0.000 0.000 0.000 0.000 0.000 -1.000 -0.826]]<jupyter_text>i6:<jupyter_code>i6 = -0.826/-1
print(i6)<jupyter_output>0.826<jupyter_text>i5:<jupyter_code>i5 = -1.976/-8.976
print(i5)<jupyter_output>0.22014260249554365<jupyter_text>i4:<jupyter_code>i4 = (-0.933 + 0.933*i5)/-1.133
print(i4)<jupyter_output>0.6421950148911366<jupyter_text>i3:<jupyter_code>i3 = (-25*i5 + 10*i4)/-5
print(i3)<jupyter_output>-0.1836770173045549<jupyter_text>i2:<jupyter_code>i2 = 5*i3/-25
print(i2)<jupyter_output>0.03673540346091098<jupyter_text>i1:<jupyter_code>i1 = (-70+20*i5+25*i2)/-75
print(i1)<jupyter_output>0.8623835048475513<jupyter_text>Exercício 12.27   Utilizando eliminação de Gauss com pivotamento (pivotamento executado manualmente), vem: O pivotamento cumpre o propósito de evitar a divisão por zero na eliminação de Gauss, e consiste em reordenar as linhas de forma que o elemento pivô (geralmente o da diagonal principal), não seja zero.  Matriz obtida a partir das leis de Kirchoff aplicadas ao circuito elétrico:<jupyter_code>matrix = np.array([  
    
    
    [0 ,0  ,1  ,1  ,-1,  0],
    [-1,0  ,1  ,0  ,1 ,  0],  
    [-1,1  ,1  ,0  ,0 ,  0], 
    [-5,0  ,-15,0  ,0 ,-80], 
    [0 ,0  ,-20,25 ,0 , 50]              
                       ])

matrix = matrix.astype('float64')<jupyter_output><empty_output><jupyter_text>Matriz pivotada:<jupyter_code>matrix = np.array([  
    
    [-5,0  ,-15,0  ,0 ,-80],
    [-1,1  ,1  ,0  ,0 ,  0],
    [-1,0  ,1  ,0  ,1 ,  0], 
    [0 ,0  ,1  ,1  ,-1,  0],
    [0 ,0  ,-20,25 ,0 , 50]              
                       ])

matrix = matrix.astype('float64')<jupyter_output><empty_output><jupyter_text>Primeiro coeficiente:<jupyter_code>temp = matrix[1][0]/matrix[0][0]
for i in range(6): 
    matrix[1][i] -= temp*matrix[0][i]

temp = matrix[2][0]/matrix[0][0]
for i in range(6): 
    matrix[2][i] -= temp*matrix[0][i]
print(matrix)<jupyter_output>[[-5.000 0.000 -15.000 0.000 0.000 -80.000]
 [0.000 1.000 4.000 0.000 0.000 16.000]
 [0.000 0.000 4.000 0.000 1.000 16.000]
 [0.000 0.000 1.000 1.000 -1.000 0.000]
 [0.000 0.000 -20.000 25.000 0.000 50.000]]<jupyter_text>Terceiro coeficiente:<jupyter_code>temp = matrix[3][2]/matrix[2][2]
for i in range(6): 
    matrix[3][i] -= temp*matrix[2][i]

temp = matrix[4][2]/matrix[2][2]
for i in range(6): 
    matrix[4][i] -= temp*matrix[2][i]
print(matrix)<jupyter_output>[[-5.000 0.000 -15.000 0.000 0.000 -80.000]
 [0.000 1.000 4.000 0.000 0.000 16.000]
 [0.000 0.000 4.000 0.000 1.000 16.000]
 [0.000 0.000 0.000 1.000 -1.250 -4.000]
 [0.000 0.000 0.000 25.000 5.000 130.000]]<jupyter_text>Quarto coeficiente:<jupyter_code>temp = matrix[4][3]/matrix[3][3]
for i in range(6): 
    matrix[4][i] -= temp*matrix[3][i]
print(matrix)<jupyter_output>[[-5.000 0.000 -15.000 0.000 0.000 -80.000]
 [0.000 1.000 4.000 0.000 0.000 16.000]
 [0.000 0.000 4.000 0.000 1.000 16.000]
 [0.000 0.000 0.000 1.000 -1.250 -4.000]
 [0.000 0.000 0.000 0.000 36.250 230.000]]<jupyter_text>Substituição regressiva:  i5:<jupyter_code>i5 = 230.000/36.250
print(i5)<jupyter_output>6.344827586206897<jupyter_text>i4:<jupyter_code>i4 = -4 + 1.25*i5
print(i4)<jupyter_output>3.931034482758621<jupyter_text>i3:<jupyter_code>i3 = (16) -i5 /4
print(i3)<jupyter_output>14.413793103448276<jupyter_text>i2:<jupyter_code>i2 = 16 - 4*i3
print(i2)<jupyter_output>-41.6551724137931<jupyter_text>i1:<jupyter_code>i1 = (-80 + 15*i3) / 5
print(i1)<jupyter_output>27.241379310344826<jupyter_text>Exercício 12.28   Matriz obtida a partir das leis de Kirchoff aplicadas ao circuito elétrico:<jupyter_code>matrix = np.array([  
    
    [1,-1 ,-1, 0, 0, 0,  0],    
    [0, 1 , 0, 0, 1,-1,  0],     
    [0, 0 ,-4,-2, 0, 0,-20],     
    [0 ,-6, 4, 0, 8, 0,  0],    
    [0 ,0 ,-1, 1, 1, 0,  0],    
    [0 ,0 , 0,-2, 8, 5,  0]    
                       ])

matrix = matrix.astype('float64')<jupyter_output><empty_output><jupyter_text>Matriz pivotada manualmente:<jupyter_code>matrix = np.array([  
    
    [1,-1 ,-1, 0, 0, 0,  0],    
    [0, 1 , 0, 0, 1,-1,  0],     
    [0, 0 ,-4,-2, 0, 0,-20], 
    [0 ,0 ,-1, 1, 1, 0,  0], 
    [0 ,-6, 4, 0, 8, 0,  0],    
    [0 ,0 , 0,-2, 8, 5,  0]    
                       ])

matrix = matrix.astype('float64')<jupyter_output><empty_output><jupyter_text>Segundo coeficiente:<jupyter_code>temp = matrix[4][1]/matrix[1][1]
for i in range(7): 
    matrix[4][i] -= temp*matrix[1][i]
print(matrix)<jupyter_output>[[1.000 -1.000 -1.000 0.000 0.000 0.000 0.000]
 [0.000 1.000 0.000 0.000 1.000 -1.000 0.000]
 [0.000 0.000 -4.000 -2.000 0.000 0.000 -20.000]
 [0.000 0.000 -1.000 1.000 1.000 0.000 0.000]
 [0.000 0.000 4.000 0.000 14.000 -6.000 0.000]
 [0.000 0.000 0.000 -2.000 8.000 5.000 0.000]]<jupyter_text>Terceiro coeficiente:<jupyter_code>temp = matrix[3][2]/matrix[2][2]
for i in range(7): 
    matrix[3][i] -= temp*matrix[2][i]

temp = matrix[4][2]/matrix[2][2]
for i in range(7): 
    matrix[4][i] -= temp*matrix[2][i]
print(matrix)<jupyter_output>[[1.000 -1.000 -1.000 0.000 0.000 0.000 0.000]
 [0.000 1.000 0.000 0.000 1.000 -1.000 0.000]
 [0.000 0.000 -4.000 -2.000 0.000 0.000 -20.000]
 [0.000 0.000 0.000 1.500 1.000 0.000 5.000]
 [0.000 0.000 0.000 -2.000 14.000 -6.000 -20.000]
 [0.000 0.000 0.000 -2.000 8.000 5.000 0.000]]<jupyter_text>Quarto coeficiente:<jupyter_code>temp = matrix[4][3]/matrix[3][3]
for i in range(7): 
    matrix[4][i] -= temp*matrix[3][i]
    
temp = matrix[5][3]/matrix[3][3]
for i in range(7): 
    matrix[5][i] -= temp*matrix[3][i]
print(matrix)<jupyter_output>[[1.000 -1.000 -1.000 0.000 0.000 0.000 0.000]
 [0.000 1.000 0.000 0.000 1.000 -1.000 0.000]
 [0.000 0.000 -4.000 -2.000 0.000 0.000 -20.000]
 [0.000 0.000 0.000 1.500 1.000 0.000 5.000]
 [0.000 0.000 0.000 0.000 15.333 -6.000 -13.333]
 [0.000 0.000 0.000 0.000 9.333 5.000 6.667]]<jupyter_text>Quinto coeficiente:<jupyter_code>temp = matrix[5][4]/matrix[4][4]
for i in range(7): 
    matrix[5][i] -= temp*matrix[4][i]
print(matrix)<jupyter_output>[[1.000 -1.000 -1.000 0.000 0.000 0.000 0.000]
 [0.000 1.000 0.000 0.000 1.000 -1.000 0.000]
 [0.000 0.000 -4.000 -2.000 0.000 0.000 -20.000]
 [0.000 0.000 0.000 1.500 1.000 0.000 5.000]
 [0.000 0.000 0.000 0.000 15.333 -6.000 -13.333]
 [0.000 0.000 0.000 0.000 0.000 8.652 14.783]]<jupyter_text>i6:<jupyter_code>i6 = 14.783/8.652
print(i6)<jupyter_output>1.7086222838650025<jupyter_text>i5:<jupyter_code>i5 = (6.000*i6 - 13.333)/15.333
print(i5)<jupyter_output>-0.20095651841192105<jupyter_text>i4:<jupyter_code>i4 = (5-i5)/1.5
print(i4)<jupyter_output>3.4673043456079475<jupyter_text>i3:<jupyter_code>i3 = (-20 + 2*i4)/-4
print(i3)<jupyter_output>3.266347827196026<jupyter_text>i2:<jupyter_code>i2 = i6-i5
print(i2)<jupyter_output>1.9095788022769236<jupyter_text>i1:<jupyter_code>i1 = i2+i3
print(i1)<jupyter_output>5.17592662947295
{'fraction_non_alphanumeric': 0.1995287385340402, 'fraction_numerical': 0.2514516536228225, 'mean_word_length': 3.1683619782532446, 'pattern_counts': {'":': 0, '<': 132, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '41', 'dir': 'jupyter-structured-clean-dedup', 'id': '667271', 'license': 'MIT', 'n_tokens_mistral': 7496, 'n_tokens_neox': 5725, 'n_words': 1101, 'path': 'APS2-sistemas-de-equacoes-matrizes.ipynb', 'repo_name': 'alcapriles/seven', 'size': '11883'}