Question: Create a function in MATLAB: function [ ] = eigen(A) The function eigen(A) will have a set of commands which will produce the following outputs
Create a function in MATLAB: function [ ] = eigen(A)
The function eigen(A) will have a set of commands which will produce the following outputs for an n x n 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!
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 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*P-P*D) 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. 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. Note: 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
