Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for Diagonal Dominate Matrix In Julia

Tags:

julia

I'm working on a project in Julia where I create a 13x13 matrix with random numbers, then I check if that matrix is diagonally dominate. I'm pretty new with Julia, but I've worked a lot with some other prgrams so this program is kind of an iteration off of 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

I understand the declaration of the j and i at the start is a little redundant but for now I leave them there. My issue is that I keep getting false even though I know that the matrix G=A'A is diagonally dominate.

like image 547
Luke Avatar asked Oct 28 '25 04:10

Luke


1 Answers

Assuming that your definition is the following:

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

You can use this code to check whether matrix a is diagonally dominant (requires using LinearAlgebra):

all(sum(abs.(a),dims=2) .<= 2abs.(diag(a)))
like image 185
Przemyslaw Szufel Avatar answered Oct 30 '25 01:10

Przemyslaw Szufel