Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Explanation / Answer

Hi below i have written a sample code for your reference, function [Xsub,idx]=licols(X,tol) %Extract a linearly independent set of columns of a given matrix X % % [Xsub,idx]=licols(X) % %in: % % X: The given input matrix % tol: A rank estimation tolerance. Default=1e-10 % %out: % % Xsub: The extracted columns of X % idx: The indices (into X) of the extracted columns if ~nnz(X) %X has no non-zeros and hence no independent columns Xsub=[]; idx=[]; return end if nargin= tol*diagr(1), 1, 'last'); %rank estimation idx=sort(E(1:r)); Xsub=X(:,idx);