If a matrix A has dimension n×n and has n linearly independent eigenvectors, it
ID: 3733352 • Letter: I
Question
If a matrix A has dimension n×n and has n linearly independent eigenvectors, it is diagonalizable. This means there exists a matrix P such that P 1AP = D, where D is a diagonal matrix, and the diagonal is made up of the eigenvalues of A. P is constructed by taking the eigenvectors of A and using them as the columns of P. Your task is to write a program (function) that does the following • Finds the eigenvectors of an input matrix A • Checks if the eigenvectors are linearly independent (think determinant) – if they are not linearly depended, exit the program & display error • Displays P, P 1 and D (if possible) • Shows that P DP 1 = A Show that your program works with a 3×3 matrix A
Explanation / Answer
EXECUTABLE CODE:
Possible solution of this probelm will be follwoing programme.Try to execute and see the result....
A=[5 -2 -2; 7 -4 -2; 3 1 -1] %This matrix is taken as input you can change accordingly
[P,D]=eig(A) %This will generate eigen vectors along with diagonal matrix of Matrix A
[m,n]=size(P)
for i=1:m
for j=1:n
fprintf('%d',P(i,j))
end
end
d=det(P)
if d==0
fprintf('Error!!!')
exit;
end
p_inv=inv(P)
[m1,n1]=size(p_inv)
for i=1:m1
for j=1:n1
fprintf('%d',p_inv(i,j))
end
end
[m2,n2]=size(D)
for i=1:m2
for j=1:n2
fprintf('%d',D(i,j))
end
end
X=P*D*(p_inv) %x will show copy of Matrix A
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.