我正在基于“多重网格教程,2ed”实现一个代数多重网格求解器,在第3章中,延长算子的形成在下面的附图中进行了描述。我的困惑来自于描述如何选择延长矩阵
P = I_{2h}^{h}
中的系数的方程,并且我不清楚如何迭代 j = 0:(n_div2_minus1)
来制定 P
。任何提示都会很棒,因为矩阵运算的公式在多重网格文献(以及一般的数值方法)中出现很多,而且我总是发现将这些运算转换为矩阵不太直观(尽管对于有限差分/有限元等情况) ,这个逻辑可以在很多文本中找到)。
julia> n_div2_min1 = 3
julia> n_min1 = 7
julia> P = zeros(n_min1, n_div2_min1)
julia> for i 1:n_min1 # rows in P, obviously this code won't work
for j in 0:n_min1
P[i, j] = 1 # this would fail for P[1, 0]
P[i, j] = 1/2 # would overwrite the previous assignment
P[i, j+1] = 1/2
end
end
这应该提供前进的方向(可以调整为采用更大的
2n+1
参数作为 N
,或乘以 1//2):
Pmat(n) = [abs(i-2j) < 2 ? i==2j ? 2 : 1 : 0 for i=1:2n+1,j=1:n]
例如,
julia> Pmat(3)
7×3 Matrix{Int64}:
1 0 0
2 0 0
1 1 0
0 2 0
0 1 1
0 0 2
0 0 1