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

Exercise 1 (6 points) In this exercise, you will find all eigenvalues of a given

ID: 3111262 • Letter: E

Question

Exercise 1 (6 points) In this exercise, you will find all eigenvalues of a given matrix A. Then you will choose the distinct eigenvalues and, for each eigenvalue, you will find a “rational” basis (if it exists) for the corresponding eigenspace and the dimension of that eigenspace. Then, you will decide whether A is diagonalizable by applying the general theory. If the matrix A is diagonalizable, the output has to contain an invertable matrix P and the diagonal matrix D, such th

**Create a function in MATLAB:

function [ ] = eigen(A)

Your function eigen(A) will have a set of commands which will produce the following outputs for an matrix A (each output has to be supplied with the corresponding message - you could use the commands disp, or fprintf, or sprintf):

(1) A row vector L (use the command transpose) of all eigenvalues – each eigenvalue repeats as many times as its multiplicity. You should also use closetozeroroundoff function (the code is below) to ensure that zero eigenvalues will be the 0. The basic MATLAB command for this part is eig(A) which returns a column vector of all eigenvalues of A.

(2) A row vector M of all distinct eigenvalues (no repetition is allowed). The MATLAB command unique can be used here (see help unique).

(3) The sum of the multiplicities, Q, of all eigenvalues (Q must to be equal to n) with the message: “The sum of multiplicities of the eigenvalues is Q =” (output Q).

(4) For each distinct eigenvalue, the output has to include a “rational” basis W for the corresponding eigenspace and its dimension. An appropriate command in MATLAB that creates a rational basis by using the row-operations is null( ,'r'). (Note: command null( ) creates an orthonormal basis for the null space – use help null command in MATAB for more information). Within the code for this part, BONUS points can be earned (see (7) below).

(5) The total sum N of the dimensions of all eigenspaces with the message: “The total sum of the dimensions of the eigenspaces is N =” (output N). The value of N has to be compared with Q (or n) and, based on the comparison, one of the two messages has to be displayed: “Yes, matrix A is diagonalizable since N=Q” or “No, matrix A is not diagonalizable since N<Q”. If matrix A is not diagonalizable, the program terminates.

(6) If A is diagonalizable output the matrix P whose columns are the bases for the eigenspaces, which you have calculated above, and the diagonal matrix D with the corresponding eigenvalues on the main diagonal (you will need to sort the entries of L to ensure that D would be constructed properly – use the MATLAB command sort when calculating L). Verify that the matrix F=closetozeroroundoff(A) is the zero matrix. If it is the case, the output has to be the message: “Great! I got a diagonalization!” And, if it is not the case, the output will be the message: “Oops! I got a bug in my code.”

(7) (BONUS! 2 points) display the multiplicity of each eigenvalue in part (4). Compare each multiplicity with the dimension of the corresponding eigenspace and, if they do not match, display a message: “Matrix A is not diagonalizable since the dimension of the eigenspace is less than the multiplicity of the corresponding eigenvalue”.

The MATLAB for loop can be used to write the code, if needed, along with the MATLAB functions eig, null( ,’r’), size within your code.

**Create the function closetozeroroundoff in MATLAB. Here is the code:

function B=closetozeroroundoff(A)

[m,n]=size(A);

for i=1:m

            for j=1:n

                        if abs(A(i,j))<10^(-7)

                                    A(i,j) = 0;

                        end

            end

end

B=A;

Below is a possible code for J = jord(n, r) that creates an Jordan block matrix with r on the main diagonal, 1’s on the diagonal above, and with all other entries 0’s.

**Create the function jord is MATLAB

function J = jord (n, r)

A = ones(n);

J = tril(triu(A),1);

for i = 1: n

            J(i, i) = r;

end

INSTRUCTIONS:

**Type the functions eigen, closetozeroroundoff, and jord in your diary file.

**Run the function eigen(A) on the following matrices:

c) A = jord(5,3); (d) A = diag([3, 3, 3, 2, 2, 1]); (e) A = magic(4); (f) A= ones(5); (g) A = magic(5).

% Place a comment in your diary file on a result that you have received for the matrix in (g). Justify whether it is correct or not and explain why. If it is not correct, make a change to your code (you might need to replace a rational bases for eigenspaces null( ,'r') with null( )) that will give you the correct set of outputs. Call it the new function eigen_1, type it in the diary file, and explain in words what change you have made in the function eigen to fix a “problem”. Run the function eigen_1 on the matrix in (g).

Explanation / Answer

the problem is running perfectly well on my matlab latest version with few coding changing in the above programming ..Try to execute the same