three_point_upwind_uni_d1.m
来自「有关the method of line即MOL算法的matlab代码」· M 代码 · 共 64 行
M
64 行
function [D]=three_point_upwind_uni_D1(z0,zL,n,v)
%...
%... A. Vande Wouwer, P. Saucez and W.E. Schiesser (2002)
%...
%... function three_point_upwind_uni_D1 returns the differentiation matrix
%... for computing the first derivative, xz, of a variable x over the spatial
%... domain z0 < z < zL from upwind three-point, first-order finite difference
%... approximations (this function replaces dss014)
%...
%... argument list
%...
%... z0 lower boundary value of z (input)
%...
%... zL upper boundary value of z (input)
%...
%... n number of grid points in the z domain including the
%... boundary points (input)
%...
%... v fluid velocity (positive from left to right - only the sign is used) (input)
%...
%... origin of the approximation
%...
%... this function is an application of second-order directional
%... differencing in the numerical method of lines. It is intended
%... specifically for the analysis of convective systems modelled by
%... first-order hyperbolic partial differential equations as dis-
%... cussed in the two_point function. The coefficients of the finite
%... difference approximations used herein are taken from Bickley, W.
%... G., Formulae for numerical differentiation, The Mathematical
%... Gazette, pp. 19-27, 1941, n = 2, m = 1, p = 0, 1, 2.
%...
%... compute the spatial increment
dz=(zL-z0)/(n-1);
r2fdz=1/(2*dz);
%...
%... (1) finite difference approximation for positive v
if v > 0
%...
%... sparse discretization matrix
%...
%... interior points
D=diag(+1*ones(n-2,1),-2)+diag(-4*ones(n-1,1),-1)+diag(+3*ones(n,1),0);
%...
%... boundary points
D(1,1:3) = [-3 +4 -1];
D(2,1:3) = [-1 0 +1];
end;
%...
%... (2) finite difference approximation for negative v
if v < 0
%...
%... sparse discretization matrix
%...
%... interior points
D=diag(-3*ones(n,1),0)+diag(+4*ones(n-1,1),+1)+diag(-1*ones(n-2,1),+2);
%...
%... boundary points
D(n-1,(n-2):n) = [-1 0 +1];
D(n,(n-2):n) = [+1 -4 +3];
end;
%...
D=r2fdz*D;
D=sparse(D);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?