Create a Function in MATLAB function L = diagonal(A) Begin the function with the
ID: 3687172 • Letter: C
Question
Create a Function in MATLAB
function L = diagonal(A)
Begin the function with the commands
n=size(A,1)
[P,D] = eig(A);
________________________________________________________
(Note: these two lines indicate that you will get n as a direct output but not [P, D].)
The command [P, D] = eig(A) produces a diagonal matrix D of eigenvalues and a full matrix P whose columns are corresponding eigenvectors so that AP=PD. Obviously, if P is invertible, its columns form a basis for R^n and A is diagonalizable. If P is not invertible, the matrix A is not diagonalizable, or equivalently, A does not have enough linearly independent eigenvectors that would form a basis for R^n . To output P, you should verify that P has exactly n linearly independent columns. Within your function diagonal, you will find the number k of linearly independent columns of P and output a message:
“The number of linearly independent columns in P is k = (your value)). Comparing k with n, you should make a conclusion whether A is diagonalizable.
If A is diagonaliziable, your output has to have two messages:
(1) "A is diagonlizable".
(2) "A basis for R^n is" (output matrix P).
If A is not diagonalizable, the output has to contain two messages:
(1) "A is not diagonlizable:.
(2) "A does not have enough linearly independent eigenvectors to create a bases for R^n".
The output for the function diagonal is the vector L of all eigenvalues of A, as indicated in the heading of the function. The row vector L has to be defined within your code as L=transpose(diag(D));
and you should run the function exactly as
L=diagonal(A)
to get the vector L as an output.
***need the code to find:
(1)number of linearly independent columns, k
(2)the basis fro R^n
(3)if matrix is diagonalizable