MATLAB: Create random diagonalisable matrix

eigenvectormatrix

hi.. I would like to create a random diagonalisable integer matrix. Is there any code for that? thereafter I would want to create matrix X such that each the columns represent the eigenvectors.

Best Answer

Hi Gary,
another way:
n = 7 % A is nxn
m = 9 % random integers from 1 to m
X = randi(m,n,n)
D = round(det(X))
lam = 1:n % some vector of unique integer eigenvalues, all nonzero
lamD = lam*D % final eigenvalues
A = round(X*diag(lamD)/X)
A*X - X*diag(lamD) % check
If n is too large and m is too small, this doesn't work sometimes because X comes up as a singular matrix.