How to avoid numerical errors when computing the Jordan form

9 views (last 30 days)
Hello.
I've managed to get a script working that will calculate the jordan form for a specified matrix consisting of integer elements.I know it is working in theory, but the problem is that when the rankings are calculated it sometimes gives the wrong answer for certain matrices like compan(poly([1:10])).
Our code is the following:
function J = jordan2(A, tol)
if nargin < 2, tol = 0.01; end
[ev, mult] = heltalsev(A, tol);
J = [];
for i= 1:length(ev)
status = false;
j = 1;
%Clear variables
clear p;
clear n;
clear b;
% Iterate until p_i is stationary
while status == false
T = A-ev(i)*eye(size(A))
for k = 1:j-1
T = round(T*(A-ev(i)*eye(size(A))))
end
p(j) = length(A) - rank(T);
if j>1 && (p(j) == p(j-1))
status = true;
end
j = j+1;
end
p
b = [p(1) diff(p)] % Assign b(1) = p(1), and b(i) = p(i)-p(i-1)
n = -diff(b); % Minus sign because n is calculated as b(n)-b(n+1) while diff calculates in the reverse order.
for j = 1:length(n) % j iterates through all the different types of blocks.
for k = 1:n(j) % k iterates through the amount of blocks of a certain type.
Jk = [ev(i)*eye(j) + [zeros(j-1,1) eye(j-1) ; 0 zeros(1,j-1)]]; % Construct a Jordan block of size j.
J = blkdiag(J, Jk); % Attach the Jordan block to the Jordan form.
end
end
end
end
Here the function heltalsev returns a vector of eigenvalues, ev for the input matrix A. I assume that the errors appears because of some form of numerical round off errors, but I have no idea how to handle this. How can I rewrite my program to prevent this from happening?
Thanks!

Answers (0)

Categories

Find more on Performance and Memory 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!