MATLAB: Use the diag command to find matrix and find dominant eigenvalues

diag commanddominant eigenvaluehomework

Consider the following vectors, which you can copy and paste directly into Matlab.
x = [2 1 2 6 6 5 5 5 5 5 4 6];
y = [6 5 6 2 5 2 1 2 2 6 5];
Use the vectors x and y to create the following matrix.
2 6 0 0 0 0 0 0 0 0 0 0
6 1 5 0 0 0 0 0 0 0 0 0
0 5 2 6 0 0 0 0 0 0 0 0
0 0 6 6 2 0 0 0 0 0 0 0
0 0 0 2 6 5 0 0 0 0 0 0
0 0 0 0 5 5 2 0 0 0 0 0
0 0 0 0 0 2 5 1 0 0 0 0
0 0 0 0 0 0 1 5 2 0 0 0
0 0 0 0 0 0 0 2 5 2 0 0
0 0 0 0 0 0 0 0 2 5 6 0
0 0 0 0 0 0 0 0 0 6 4 5
0 0 0 0 0 0 0 0 0 0 5 6
Such a matrix is called a tri-diagonal matrix. Hint: Use the diag command three times, and then add the resulting matrices.
To check that you have correctly created the matrix A, verify that det(A) = -4.2749e+07.
Find the dominant eigenvalue of A.

Best Answer

Rather than copying and pasting your homework assignment into the above, why not include an attempt at solving it? The question gives a hint as use the diag command three times, and then add the resulting matrices. Look at an example from diag
v = [2 1 -1 -2 -5];
diag(v)
ans =
2 0 0 0 0
0 1 0 0 0
0 0 -1 0 0
0 0 0 -2 0
0 0 0 0 -5
Which of your two vectors would you use (in the above) in place of v? Now how would you copy the other vector above or below the main diagonal? Look at the documentation for diag and the answer will be apparent.