Matlab algorithm takes as input an integer $n$, and generates a random $n$ by $n$ symmetric positive definite and strictly diagonally dominant matrix.

318 Views Asked by At

I could write an algorithm to generate a random symmetric positive definite matrix, but how to edit it to also have this matrix to be strictly diagonally dominant?

Here is my code:

function $A$ = generateSPDmatrix$(n)$ % Generate a dense n x n symmetric, positive definite matrix

$A = rand(n,n)$; % generate a random n x n matrix

% construct a symmetric matrix

$A = 0.5*(A+A')$;

% since $A(i,j) < 1$ by construction and a symmetric diagonally dominant matrix is symmetric positive definite, which can be ensured by adding nI

$A = A + n*eye(n)$;

end

1

There are 1 best solutions below

3
On BEST ANSWER

As you have recalled it, a real symmetric (more genrally Hermitian) diagonally dominant matrix ${\displaystyle A}$ with real non-negative diagonal entries is positive semidefinite (see (https://en.wikipedia.org/wiki/Diagonally_dominant_matrix))

Here is a Matlab program giving a random matrix as you desire it, in the same spirit as you.

(I think the comments I have given are enough for following the instructions; remember that operator "sum" on a matrix gives the row vector of the sums column by column):

n=5;
rng('shuffle');A=rand(n);
B=A+A';% or A*A'
C=diag(diag(B)); % extraction of the diagonal part of B
D=B-C;
m=max(sum(D)); % m is the biggest sum in columns (or in rows) of D 
E=D+m*eye(n),% the zero diagonal of D is filled with values m
eig(E), % all eigenvalues are positive