Givens rotation method to find eigen values

91 views (last 30 days)
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?
Thankyou for your efforts in advance :)
function eigen_values = given(B)
syms x
[m,n] = size(B);
if nargin>1
fprintf('Please enter only one Matrix');
% Eliminating possibilities of error and hence making code more robust
if isscalar(B) || (m ~= n)
fprintf('Please enter a Square matrix \n');
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');
S = eye(m); % Preallocating for faster computation
j =2;
N = ((m-1)*(m-2))/2; % Calculating the number of rotaions required to get Tridigonal form
I = 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 rotation
for 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);
B = S'*B*S
j =j+1;
S = eye(m);
if j >m
eqn = det(B-x*I);
eigen_values = solve(eqn);

Accepted Answer

Star Strider
Star Strider on 24 Dec 2020
Edited: Star Strider on 24 Dec 2020
Instead of solve, use vpasolve here:
eigen_values = vpasolve(eqn);
that with your ‘A’ matrix:
A =[-6 2 1;2 -9 -4; 1 -4 -9];
EV = given(A)
EV =
EDIT — (24 Dec 2020 at 17:12)
To get the result as a vector of double (rather than symbolic) values:
EV = double(EV)
EV =

More Answers (0)


Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!