Text and code provided under a Creative Commons Attribution license, CC-BY. (c) Lorena A. Barba, 2013. Thanks: Gilbert Forsyth for help writing the notebooks. NSF for support via CAREER award #1149784. import numpy as np #loading our favorite library import matplotlib.pyplot as plt #and the useful plotting library nx = 41 dx = 2./(nx-1) nt = 20 #the number of timesteps we want to calculate nu = 0.3 #the value of viscosity sigma = .2 #sigma is a parameter, we'll learn more about it later dt = sigma*dx**2/nu #dt is defined using sigma ... more later! u = np.ones(nx) #a numpy array with nx elements all equal to 1. u[.5/dx : 1/dx+1]=2 #setting u = 2 between 0.5 and 1 as per our I.C.s un = np.ones(nx) #our placeholder array, un, to advance the solution in time for n in range(nt): #iterate through time un[:] = u[:] ##copy the existing values of u into un for i in range(1,nx-1): u[i] = un[i] + nu*dt/dx**2*(un[i+1]-2*un[i]+un[i-1]) plt.plot(np.linspace(0,2,nx), u) from IPython.display import YouTubeVideo YouTubeVideo('y2WaK7_iMRI') from IPython.core.display import HTML def css_styling(): styles = open("../styles/custom.css", "r").read() return HTML(styles) css_styling()