Texto y código sujeto bajo Creative Commons Attribution license, CC-BY-SA. (c) Original por Lorena A. Barba y Gilbert Forsyth en 2013, traducido por F.J. Navarro-Brull para CAChemE.org #Representa las figuras en este mismo notebook: %pylab inline import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D ## Nueva librería requerida para proyecciones en 3D import numpy as np ### Declaración de variables nx = 81 ny = 81 nt = 100 c = 1 dx = 2.0/(nx-1) dy = 2.0/(ny-1) sigma = .2 dt = sigma*dx x = np.linspace(0,2,nx) y = np.linspace(0,2,ny) u = np.ones((ny,nx)) ## crea un vector 1xn de unos un = np.ones((ny,nx)) ## ### Asignación de las condiciones iniciales # Sse establece una función de sombrero como tal # u(.5<=x<=1 && .5<=y<=1 ) is 2 u[.5/dy:1/dy+1,.5/dx:1/dx+1]=2 ### Representar condiciones iniciales fig = plt.figure(figsize=(11,7), dpi=100) ##Los parametros figsize pueden se usados para cambiar el tamño y resolución ax = fig.gca(projection='3d') X, Y = np.meshgrid(x,y) surf = ax.plot_surface(X,Y,u[:]) u = np.ones((ny,nx)) u[.5/dy:1/dy+1,.5/dx:1/dx+1]=2 for n in range(nt+1): ## Bucle para los incrementos de tiempo un[:] = u[:] for i in range(1, len(u)): for j in range(1, len(u)): u[i,j] = un[i, j] - (c*dt/dx*(un[i,j] - un[i-1,j]))-(c*dt/dy*(un[i,j]-un[i,j-1])) u[0,:] = 1 u[-1,:] = 1 u[:,0] = 1 u[:,-1] = 1 fig = plt.figure(figsize=(11,7), dpi=100) ax = fig.gca(projection='3d') surf2 = ax.plot_surface(X,Y,u[:]) u = np.ones((ny,nx)) u[.5/dy:1/dy+1,.5/dx:1/dx+1]=2 for n in range(nt+1): ## Bucle para los incrementos de tiempo un[:] = u[:] u[1:,1:]=un[1:,1:]-(c*dt/dx*(un[1:,1:]-un[0:-1,1:]))-(c*dt/dy*(un[1:,1:]-un[1:,0:-1])) u[0,:] = 1 u[-1,:] = 1 u[:,0] = 1 u[:,-1] = 1 fig = plt.figure(figsize=(11,7), dpi=100) ax = fig.gca(projection='3d') surf2 = ax.plot_surface(X,Y,u[:]) plt.show() from IPython.display import YouTubeVideo YouTubeVideo('tUg_dE3NXoY') from IPython.core.display import HTML def css_styling(): styles = open("../styles/custom.css", "r").read() return HTML(styles) css_styling()