问题描述来自:
http://my.oschina.net/cfdvalidation/blog/308374:
差分法解决代码: #!/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 - x2) 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()