Escolar Documentos
Profissional Documentos
Cultura Documentos
TRABALHO PRÁTICO 1:
RELATÓRIO FINAL
Professor:
Eduardo Camponogara
Alunos:
Bruno Forte de Lunardi Pinto - 22102525
Marcus Vinicius Novais Ferrari - 22104098
Paulo Librelotto Ferroli - 22100768
Victória De Carvalho Taveira - 21202235
Florianópolis
2023
SUMÁRIO
1 QUESTÃO 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 MÉTODO DA BISSECÇÃO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 MÉTODO DA FALSA POSIÇÃO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 MÉTODO DE NEWTON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4 MÉTODO DAS SECANTES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 QUESTÃO 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1 ITEM 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 ITEM 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 ITEM 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3 QUESTÃO 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1 SISTEMA DE EQUAÇÕES LINEARES A SER RESOLVIDO . . . . . . . . . . . . . . 15
3.2 PROGRAMAÇÃO DO MÉTODO DE ELIMINAÇÃO GAUSSIANA . . . . . . . . . 15
3.3 SOLUÇÃO FINAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4 QUESTÃO 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.1 ITEM 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 ITEM 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 ITEM 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.4 ITEM 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.5 ITEM 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1
1 QUESTÃO 1
x_values = []
error_values = []
interval_a_values = []
interval_b_values = []
#Armazena os valores
x_values.append(m)
error_values.append(er)
interval_a_values.append(a)
interval_b_values.append(b)
it += 1
if m == mold:
break
2
#Plotando os gráficos
plt.figure(figsize=(12, 8))
plt.subplot(2, 2, 1)
plt.plot(range(1, it+1), x_values, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’x_k’)
plt.title(’Iterações de x_k’)
plt.subplot(2, 2, 2)
plt.plot(range(1, it+1), error_values, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’|A(x)|’)
plt.title(’Erros |A(x)|’)
plt.subplot(2, 2, (3,4))
plt.plot(range(1, it+1), interval_a_values, marker=’o’, label=’a_k’, color=’blue’)
plt.plot(range(1, it+1), interval_b_values, marker=’o’, label=’b_k’, color=’red’)
plt.xlabel(’Iterações’)
plt.ylabel(’[a_k,b_k]’)
plt.title(’Intervalos [a_k,b_k]’)
plt.legend()
plt.tight_layout()
plt.show()
m = a
er = 1
x_values = []
error_values = []
interval_a_values = []
interval_b_values = []
it += 1
if m == mold:
break
plt.subplot(2, 2, 1)
plt.plot(range(1, it+1), x_values, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’x_k’)
plt.title(’Iterações de x_k’)
plt.subplot(2, 2, 2)
plt.plot(range(1, it+1), error_values, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’|A(x)|’)
plt.title(’Erros |A(x)|’)
plt.subplot(2, 2, (3,4))
plt.plot(range(1, it+1), interval_a_values, marker=’o’, label=’a_k’, color=’blue’)
plt.plot(range(1, it+1), interval_b_values, marker=’o’, label=’b_k’, color=’red’)
5
plt.xlabel(’Iterações’)
plt.ylabel(’[a_k,b_k]’)
plt.title(’Intervalos [a_k,b_k]’)
plt.legend()
plt.tight_layout()
plt.show()
linear. Ele começa com um intervalo inicial [a, b] que contém a raiz e em cada iteração,
é calculado um novo valor médio m baseado na fórmula da falsa posição, tendo portanto,
uma taxa de convergência linear, não sendo também o mais eficiente.
#Armazena os valores
error_values.append(er)
x_values.append(x)
it += 1
if x == xold:
break
plt.subplot(2, 2, 1)
plt.plot(range(1, it+1), x_values, marker=’o’)
7
plt.xlabel(’Iterações’)
plt.ylabel(’x_k’)
plt.title(’Iterações de x_k’)
plt.subplot(2, 2, 2)
plt.plot(range(1, it + 1), error_values, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’|A(x)|’)
plt.title(’Erros |A(x)|’)
plt.tight_layout()
plt.show()
import math
import numpy as np
import matplotlib.pyplot as plt
x_values = []
error_values = []
interval_a_values = []
interval_b_values = []
#Armazena os valores
x_values.append(x)
error_values.append(er)
interval_a_values.append(xa1)
interval_b_values.append(xa2)
it += 1
if (x == xa1):
break
plt.subplot(2, 2, 1)
plt.plot(range(1, it + 1), x_values, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’x_k’)
plt.title(’Valores de x nas iterações’)
plt.subplot(2, 2, 2)
plt.plot(range(1, it + 1), error_values, marker=’o’)
plt.xlabel(’Iterações’)
9
plt.ylabel(’|A(x)|’)
plt.title(’Erros |A(x)|’)
plt.tight_layout()
plt.show()
2 QUESTÃO 2
2.1 ITEM 1
A raiz aproximada encontrada, com precisão de 10−9 , através do código abaixo foi:
1.5458515577832742e-16.
2.2 ITEM 2
return b
return A
x_values = []
residual_norms = []
errors = []
x0 = x1
it = len(x_values)
x_values = np.array(x_values).T
# Plotar os gráficos
plt.figure(figsize=(12, 8))
plt.subplot(2, 2, 1)
plt.plot(range(1, it + 1), residual_norms, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’||f(x(k))||2’)
plt.title(’Resíduos f(x(k))2’)
plt.subplot(2, 2, 2)
plt.plot(range(1, it + 1), errors, marker=’o’)
plt.xlabel(’Iterações’)
plt.ylabel(’x(k) x2’)
plt.title(’Erro x(k) x2’)
13
plt.tight_layout()
plt.show()
#Plotar em 3D
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111, projection=’3d’)
x = x_values[0]
y = x_values[1]
z = x_values[2]
ax.set_xlabel(’X’)
ax.set_ylabel(’Y’)
ax.set_zlabel(’Z’)
plt.title(’Iterandos x(k) em 3D’)
plt.show()
2.3 ITEM 3
14
15
3 QUESTÃO 3
Em forma matricial A x = b:
3 1 2 0 1 x1 12
1 4 2 1 0 x2 20
2 0 3 4 1 x3 = 18
4 2 1 2 3 x4 22
0 2 1 3 4 x5 19
return A,b
for i in list(range(n-1,0,-1)):
s = 0
for j in list(range(i+1,n+1,1)):
s = s + U[i-1][j-1]*x[j-1]
x[i-1] = (b[i-1]-s)/(U[i-1][i-1])
return x
#Dados do problema
Ai = [[3, 1, 2, 0, 1],
[1, 4, 2, 1, 0],
[2, 0, 3, 4, 1],
[4, 2, 1, 2, 3],
[0, 2, 1, 3, 4]]
Solução:
3 1 2 0 1
0 3.6666666666666665 1.3333333333333335
1.0 −0.3333333333333333
U= 0 0 1.9090909090909092 4.181818181818182 0.27272727272727276
0 0 0 5.999999999999999 2.0
0 0 0 0 3.5238095238095233
12
16.0
b = 12.90909090909091
15.999999999999998
3.4761904761904763
1.5810810810810805
3.27027027027027
∗
1.5000000000000007
x =
2.3378378378378377
0.9864864864864866
17
4 QUESTÃO 4
4.1 ITEM 1
v0 = sp.Symbol(’v0’)
4.2 ITEM 2
def AproximacaoDerivada( v0 , h ) :
fv0 = EulerODE( v0 , 0.01 , 3) - 10
fv0_delta = EulerODE( v0 + h , 0.01 , 3)- 10
derivada = ( fv0_delta - fv0 ) / h
return derivada
AproximacaoDerivada: 1.20000698218981.
4.3 ITEM 3
v = 1
itm = 0
vitm =[]
vitm.append(v)
itm = itm + 1
plt.figure()
plt.plot(vitm)
v0=v
v0: 3.226145005743854.
4.4 ITEM 4
4.5 ITEM 5
19