del2_5pt.m

来自「有限差分中用于五点差分的matlab程序」· M 代码 · 共 35 行

M
35
字号
function [output]=del2_5pt(input,delx)
% DEL2_5PT ... compute the 5 point Laplacian
%
% [output]=del2_5pt(input,delx)
%
% DEL2_5PT computes the 5 point approximation to the laplacian operator of 
% the two dimensional matrix 'input'.  The horizontal and vertical bin
% spacing of the matrix MUST be the same.    
%
% input = input matrix
% delx = the horizontal/ vertical bin spacing in consistent units
%
% output = the output matrix



[nrows,ncolumns]=size(input);

input2=zeros(nrows+2,ncolumns+2);     %对应二阶精度的有限差分,矩阵取法
input2(2:nrows+1,2:ncolumns+1)=input;
factor=1/(delx^2);
clear input   %删除input矩阵


% for first dimension  -----可以看成对x的二阶偏导数

   output = (input2(3:nrows+2,2:ncolumns+1) - 2.*input2(2:nrows+1,2:ncolumns+1) +...
                  input2(1:nrows,2:ncolumns+1))*factor;

% for second dimension ------可以看成对z的二阶偏导数

 output = (input2(2:nrows+1,3:ncolumns+2) - 2.*input2(2:nrows+1,2:ncolumns+1) +...
                 input2(2:nrows+1,1:ncolumns))*factor+ output;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?