# MATLAB: Givens rotation method to find eigen values

eigenvaluesgivens methodgivens rotation method

The below code is to obtain eigen value with the help of Givens rotation method, where the matrix is converted into tridigonal form first and then its eigenvalues are obtained.
The code below works fine for some cases but doesn't give eigenvalues at certain cases.
Ex- A =[-6 2 1;2 -9 -4; 1 -4 -9];
The output is :
root(z^3 + 24*z^2 + 168*z + 361, z, 1)
root(z^3 + 24*z^2 + 168*z + 361, z, 2)
root(z^3 + 24*z^2 + 168*z + 361, z, 3)
Can anyone tell me what I have been missing?
function eigen_values = given(B)syms x[m,n] = size(B);if nargin>1    fprintf('Please enter only one Matrix');    return;end% Eliminating possibilities of error and hence making code more robustif isscalar(B) || (m ~= n)    fprintf('Please enter a Square matrix \n');    return;elseif m ==2    fprintf('Please enter a Square matrix grater than 2X2 \n');    return ;elseif ~isreal(B)    fprintf('All elements of the input matrix should belong to real number domain except infinity and negative infinity \n');    return ;elseif find((isfinite(B))==0)    fprintf('Please enter a matrix with finite number as its elements \n');    return;endS = eye(m);    % Preallocating for faster computationj =2;N = ((m-1)*(m-2))/2;  % Calculating the number of rotaions required to get Tridigonal formI = eye(m);theta = atan(B(1,j+1)/B(1,2));  %Calculating theta for first rotation%The for loop below calculates values of sine and cosine of theta %It also creates a orthogonal matrix 'S' at each rotationfor i = 1:N    fprintf('Rotation %d : \n',i);    theta = atan(B(1,j+1)/B(1,2));    S(2,2) = cos(theta);    S(2,j+1) = -sin(theta);    S(j+1,2) = sin(theta);    S(j+1,j+1) = cos(theta);    S    B = S'*B*S    j =j+1;      S = eye(m);     if j >m        break;    end    endeqn = det(B-x*I);eigen_values = solve(eqn);end

Instead of solve, use vpasolve here:
eigen_values = vpasolve(eqn);
A =[-6 2 1;2 -9 -4; 1 -4 -9];EV = given(A)
EV =-13.596915527892124341934473181412-5.9128104205174475776683632011464-4.4902740515904280803971636174419
EV = double(EV)
EV = -13.596915527892124  -5.912810420517448  -4.490274051590428