You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MATLAB中2-网格法求解离散泊松方程的实现异常问题

2-网格法求解离散泊松方程的异常问题

我正在实现求解离散泊松方程的2-网格法,为理解多重网格方法查阅了多篇论文,本次实现参考某论文第10页的示例。我认为所有步骤均已正确实现,但出现异常现象:将粗网格修正延长回细网格后,平滑误差分量本应减小,使解更接近真实值,同时误差应更具振荡性,但我的实现中误差几乎没有变化。参考另一示例第38页后,仍存在相同问题。我是否存在理解偏差?

以下是我的代码及结果:

主代码

%Grid size
m = 32 - 1;
h = 1/(m+1);
X = h:h:(1-h);

%The fine grid has m=31 points.
%The coarse grid has mr=15 points
mr = (m-1)/2;

%Restriction and prolongation matrices
%R - full weighting
R = zeros(mr, m);
for i = 0:mr-1
    R(i + 1, 2*i + 1) = 1/4;
    R(i + 1, 2*i + 2) = 1/2;
    R(i + 1, 2*i + 3) = 1/4;
end

%P - linear interpolation
P = zeros(m, mr);
for j = 0:mr-1
    P(2*j + 1, j + 1) = 1/2;
    P(2*j + 2, j + 1) = 1;
    P(2*j + 3, j + 1) = 1/2;
end

%------------------------------------------
%I'll be solving discrete Poisson equation
%-∇^2 u = f
%u(0)=u(1)=0

%Given function f
f = 25*pi^2*(sin(5*pi*X) + 9*sin(15*pi*X));

%System of equations Ax=b with initial guess x=0
%tridiag produces a square m by m matrix
A = tridiag(-1, 2, -1, m);
b = f' * h^2;
x = zeros(m,1);

%Analytic solution
u = sin(5*pi*X) + sin(15*pi*X);

%------------------------------------------
%Multigrid

%Pre-smoothing
%3 iterations of weighted Jacobi method with w=2/3
x = Jacobi(A,x,b,2/3,3);

%Up to this point everything is fine

%Restric the residue r -> rr
r = b - A * x;
rr = R * r;

%Ae = r on the coarse grid
Ar = tridiag(-1, 2, -1, mr);
er = zeros(mr,1);
%4 iterations of weighted Jacobi method with w=2/3
er = Jacobi(Ar,er,rr,2/3,4);

%Prolongation er -> e
e = P * er;
x = x + e;

Jacobi函数实现

function x = Jacobi(A, x0, b, w, Imax)
    n = size(x0, 1);
    x = zeros(n,1);
    I = 0;
    while I < Imax
        for i = 1:n
            x(i) = w/A(i,i) * (b(i) - sum(A(i,:)'.*x0) + A(i,i)*x0(i)) + (1-w)*x0(i);
        end
        x0 = x;
        I = I + 1;
    end
end

结果图

误差对比曲线

内容的提问来源于stack exchange,提问作者Cymek3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 21:05:12