• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 24th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import numpy as np
2. import matplotlib.pyplot as plt
3.
4. #
5. # Específico para a matriz do exercício
6. def build_matrix(ny, nx):
7.     empty_matrix = np.zeros((ny, nx))
8.     for i in range (nx):
9.         for j in range (ny):
10.             if (i == (ny-1)):            # horizontal baixo
11.                 empty_matrix[i][j] = 150
12.             elif(j == 0):                # vertical esquerda
13.                 empty_matrix[i][j] = 23
14.             elif(i == 0):                # horizontal cima
15.                 empty_matrix[i][j] = 23
16.             elif(j == (nx-1)):           # vertical direita
17.                 empty_matrix[i][j] = 23
18.             else:
19.                 empty_matrix[i][j]= -1
20.     return empty_matrix
21.
22. def solve_matrix(act_matrix, nx, ny, alpha, nopline):
23.     nxt_matrix = build_matrix(ny, nx)
24.     for i in range (nx):
25.         for j in range (ny):
26.             if (i-1 > nopline):
27.                 if (nxt_matrix[i][j] == -1):
28.                     nxt_matrix[i][j] = alpha * 0.01  * ((act_matrix[i+1][j]+act_matrix[i-1][j]-2*act_matrix[i][j])/0.01 + (act_matrix[i][j+1]+act_matrix[i][j-1]-2*act_matrix[i][j])/0.01) + act_matrix[i][j]
29.             else:
30.                 nxt_matrix[i][j]=23
31.
32.     return nxt_matrix
33.
34.
35.
36. act_matrix = build_matrix(100, 100) # para 50 cm de 10 em 10 cm
37. for i in range (50):
38.     for j in range (50):
39.         if (act_matrix[i][j] == -1):
40.             act_matrix[i][j] = 0
41.
42.
43. for _ in range(1000):
44.     act_matrix = solve_matrix(act_matrix, 50, 50, 0.25, 20)
45.
46. #print(act_matrix)
47.
48.
49.
50. plt.imshow(act_matrix)
51. plt.colorbar()
52. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top