In: Computer Science
MATLAB CODE:
A particular 3x3 linear transformation A has eigenvalues of -1, 2, and 4, and corresponding eigenvectors with directions of [1;1;0], [0;1;l], and [1;1;1], respectively. Because eigenvectors must have unit length, you will need to normalize the given vectors by the length of each array to find the actual eigenvectors. Given this information, and using the eigen decomposition, find the linear transformation A. Hint: you can use the diag() function to form the D matrix from the provided eigenvalues. Once A is found, verify your answer using the Matlab eig() function, which takes an n x n matrix A as an argument and returns the eigenvector (P2) and diagonal eigenvalue (D2) matrices associated with A: [P2,D2] = eig(A)P and P2 should share the same columns, while D and D2 should share the same diagonal elements
Follow the comments in the code to understand:
%% create a diagonal matrix from the given eigen values
D = diag([4,2,-1],3,3)
%% Normalize the vectors
%% To normalize, divide the vector by its magnitude
p3 = [1/sqrt(3); 1/sqrt(3); 1/sqrt(3)];
p2 = [0; 1/sqrt(2); 1/sqrt(2)];
p1 = [1/sqrt(2); 1/sqrt(2);0];
%% create the modal matrix p
P = [p3,p2,p1]
%% find the original matrix by the formula A = P D P^-1
A = P*D*inv(P)
%% find the values using matlab
[P2, D2] = eig(A)
Output:
D =
Diagonal Matrix
4 0 0
0 2 0
0 0 -1
P =
0.57735 0.00000 0.70711
0.57735 0.70711 0.70711
0.57735 0.70711 0.00000
A =
4 -5 5
2 -3 5
2 -2 4
P2 =
-5.7735e-01 -4.4869e-16 -7.0711e-01
-5.7735e-01 7.0711e-01 -7.0711e-01
-5.7735e-01 7.0711e-01 3.8858e-16
D2 =
Diagonal Matrix
4.00000 0 0
0 2.00000 0
0 0 -1.00000
Notice that although the diagonal matrix D2 and D are same , the values of columns of P and P2 are not same[but equivalent]. Why are they equivalent? Because the eigen vector corresponding to an eigen vector E are kE, where k is any constant. i.e., corresponding to [1;1;0] there are infinite number of eigen vectors such as [2;2;0] , [-3;-3;0] etc. Both are different but represent the same eigen vector.
Also the values are close to 0 but not exaclty 0 in P2 because matlab uses floating point arithmetic which produces approximate results.