dss012=function(xl,xu,n,u,v) { # # Function dss012 computes the first order finite difference approximation # of a first derivative # # Declare arrays ux=rep(0,n); # # Grid spacing dx=(xu-xl)/(n-1); # # Finite difference approximation for positive v if(v > 0){ ux[1]=(u[2]-u[1])/dx; for(i in 2:n){ ux[i]=(u[i]-u[i-1])/dx;} } # # Finite difference approximation for negative v if(v < 0){ for(i in 1:(n-1)){ ux[i]=(u[i+1]-u[i])/dx;} ux[n]=(u[n]-u[n-1])/dx; } # # All points concluded (x=xl,...,x=xu) return(c(ux)); }