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 th

ID: 1839475 • 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);

________________________________________________________

Within your function, you will find the number k of linearly independent columns in P and ouput 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:

(1) A message: "A is diagonlizable".

(2) A message: "A basis for R^n is" (output matrix P).

If A is not diagonalizable, the output has to contain

(1) A message: "A is not diagonlizable:.

(2) A message: "A does not have enough linearly independent eigenvectors to create a bases for R^n".

The "answer" for the function diagonal is the vector L of all the 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.

Explanation / Answer

function L = diagonal(A)
A=input('Enter elements of the matrix');
n = size(A,1);
[P,D] = eig(A);
k=rank(D);

disp('The number of linearly independent columns in P is k = ');
k
if (k==n)
disp('A is diagonlizable');
disp('A basis for R^n is');
P
else
disp('A is not diagonlizable');
disp('A does not have enough linearly independent eigenvectors to create a bases for R^n');
end

%% Enter input in matrix FORM like [ 1 2 3 ; 1 3 5 ; 3 2 6] so on