差分法与傅里叶谱方法计算拉普拉斯算子

使用差分法和傅里叶谱方法求解拉普拉斯算子

%Test laplacian operator with difference method and fourier spectral method
clear;close all;
Nx = 128;Ny=Nx;dx=1;dy=dx;
%% Generage Gaussian Distribution
X = 0 : 1 : Nx-1;Y = 0 : 1: Ny-1;
fangcha= 100;fangcha2 = 220;
u1 = zeros(Nx, Ny);
u2 = zeros(Nx,Ny); 
%A = 10 ^ 5;
A=1;
center_u1 = 50;
for row = 1 : 1 : Nx
    for col = 1 : 1 : Ny
        u1(row, col) = (X(row) - center_u1) .* (X(row)-center_u1) + (Y(col) - center_u1) .* (Y(col) - center_u1);
    end
end
u1 = -u1/(2*fangcha);
u1 = A * exp(u1) / (sqrt(2*pi) * sqrt(fangcha));
surf(X, Y, u1);surf(X, Y, u2);

%% Calculate Laplacian with Difference Method 
lap_u1_diff = laplacian_var(Nx,Ny,dx,dy,u1);

%% Calculate Laplacian with Spectral Method
[kx,ky,kX,kY,k2,k4] = prepare_fft(Nx,Ny,dx,dy);
lap_u1_spectral_method = real(ifft2(-1*k2.*fft2(u1)));
figure(1);
subplot(2,2,1);imagesc(lap_u1_diff);colorbar;title('lap u1 DifferenceMethod');
subplot(2,2,2);imagesc(lap_u1_spectral_method);colorbar;title('lap u1 SpectralMethod');
subplot(2,2,3);mesh(lap_u1_diff);colorbar;title('lap u1 DifferenceMethod');
subplot(2,2,4);mesh(lap_u1_spectral_method);colorbar;title('lap u1 SpectralMethod');
error = lap_u1_diff - lap_u1_spectral_method;
error_sum = sum(error(:));

这里写图片描述

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值