dss002=function(xl,xu,n,u) { # # An extensive set of documentation comments detailing the derivation # of the following second order finite differences (FDs) is not given # here to conserve space. The comments are available in the Matlab # version of dss002 in http://www.pdecomp.net. The derivation is also # detailed in Schiesser, W. E., The Numerical Method of Lines Integration # of Partial Differential Equations, Academic Press, San Diego, 1991. # # Preallocate arrays ux=rep(0,n); # # Grid spacing dx=(xu-xl)/(n-1); # # 1/(2!*dx) for subsequent use r2fdx=1/(2*dx); # # ux vector # # Boundaries (x=xl,x=xu) ux[1]=r2fdx*(-3*u[1]+4*u[ 2]-u[ 3]); ux[n]=r2fdx*( 3*u[n]-4*u[n-1]+u[n-2]); # # Interior points (x=xl+dx,...,x=xu-dx) for(i in 2:(n-1))ux[i]=r2fdx*(u[i+1]-u[i-1]); # # All points concluded (x=xl,...,x=xu) return(c(ux)); }