问题描述来自 :http://my.oschina.net/cfdvalidation/blog/308489
#!/usr/bin/python import numpy as np import matplotlib.pylab as plt import time,sys nx = 41 dx = 2.0/(nx-1) nt=25 dt=0.025 c = 1. def fun(x1,x2): x = x1 - c * (dt/dx) * x1*(x1 - x2) #只有这里与步骤一的代码不同,添加了x1哦 return x u = np.ones(nx) u[.5/dx : 1/dx+1] = 2 plt.plot(np.linspace(0,2,nx),u,label="initial") for t in range(nt): un = u.copy() for i in range(1,nx): u[i] = fun(un[i],un[i-1]) plt.plot(np.linspace(0,2,nx),u,label="converged") plt.legend(loc=' right') plt.show()