我正在 Julia 中开展一个项目,在该项目中我创建了一个包含随机数的 13x13 矩阵,然后我检查该矩阵是否是对角占优矩阵。我是 Julia 的新手,但我使用过很多其他程序,所以这个程序有点像 python 的迭代。
function checkD()
A=2*rand(13,13).-1
G=A'A
j=1
i=1
for i=1:13
sum = 0
for j=1:13
sum = sum + abs.(G[i,j])
end
sum = sum - abs.(G[i,i])
if(abs.(G[i,i]) < sum)
return false
end
return true
end
我知道开头的 j 和 i 声明有点多余,但现在我将它们留在那里。我的问题是,即使我知道矩阵 G=A'A 是对角占优的,我仍然会出错。
最佳答案
假设您的定义如下:
a diagonally dominant matrix is a square matrix such that in each row, the absolute value of the term on the diagonal is greater than or equal to the sum of absolute values of the rest of the terms in that row
您可以使用此代码来检查矩阵 a
是否对角占优(需要 using LinearAlgebra
):
all(sum(abs.(a),dims=2) .<= 2abs.(diag(a)))
关于julia - 在 Julia 中检查对角支配矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64863201/