You are on page 1of 1

import numpy as np

import matplotlib.pyplot as plt


from numpy import arange
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter

#Definindo as condições de contorno


pot2 = 1.
pot1 = 0.
comprimentox = 20
comprimentoy = 20
delta = 1 #intervalo da iteração
maxit = 500 #numero de iterações
#Criando a matriz de potencial
V = np.empty((20,20)) #Criando matriz "vazia"
V.fill(0) #preenchendo com zero
for n in range(7,13,1): #Delimitando os potenciais
V[n] = [0 ,0, 0, 0, 0 ,0 ,0, 1 ,1 ,1 ,1, 1, 1 ,0 ,0 ,0, 0, 0, 0, 0]
for iteration in range(0, maxit):
for i in range(1, comprimentox-1, delta):
for j in range(1, comprimentoy-1, delta):
V[i, j] = 0.25 * (V[i+1][j] + V[i-1][j] + V[i][j+1] + V[i][j-1])
#Atribuindo os valores para o grafico usando o meshgrid
Z = arange(pot1, pot2, 0.0001) #Z = potential no grafico..inutil ate o presente
momento
X, Y = np.meshgrid(np.arange(10-comprimentox, comprimentox-10), np.arange(10-
comprimentoy, comprimentoy-10))
############################## Definindo a parte "gráfica" do...
gráfico#############################################
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, V, cmap=cm.coolwarm,
linewidth=0, antialiased=False)

# Customize the z axis.


ax.set_zlim(0, 3e-7)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

# Add a color bar which maps values to colors.


fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

You might also like