フィルターのクリア

~isequal and ~= not working

3 ビュー (過去 30 日間)
Danielle sal
Danielle sal 2021 年 4 月 16 日
コメント済み: Walter Roberson 2021 年 4 月 17 日
so I have to vectors that are clearly different but Ive tried runnig the code with both ~isequal and ~= and still doesnt work
function [L,P,D]=eigen(A)
format
[~,n]=size(A);
P=[];
D=[];
L=eig(A);
L=transpose(L);
L=real(L);
L=sort(L);
for i= 1:n-1
Temp1 = L(i);
Temp2 = L(i+1);
if closetozeroroundoff(Temp1-Temp2, 7)== 0
L(1,i+1) = L(1, i);
end
end
if rank(L) ~= n
L = closetozeroroundoff(L,7);
end
fprintf('all eigenvalues of A are\n')
display(L)
%Part II
M = unique(L);
display(M)
m = groupcounts(transpose(L));
M = transpose(M);
for i = 1:size(M)
fprintf('eigenvalue %d has multiplicity %i\n',M(i),m(i))
end
M = unique(L);
[a,b] = size(M);
ValueOfd = zeros(1:b);
P = zeros(n,1);
for i = 1:b
space = A - (eye(n)*M(i));
W = null(space);
P = horzcat(P,W);
fprintf('a basis for the eigenspace for lambda=%d is:\n',M(i))
display(W)
d = size(W,2);
ValueOfd(i) = d;
fprintf('dimension of eigenspace for lambda = %d is %i\n',M(i),d)
end
P(:,1) = [];
%Part 3
disp(m)
disp(transpose(ValueOfd))
if ~eq(transpose(ValueOfd), m)
disp("A is not diagonalizable")
else
disp("A is diagonalizable")
This is the function ad then I run it for
%(b)
A=[2 4 3;-4 -6 -3;3 3 1]
[L,P,D]=eigen(A);
any idea on how to fix this?

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 17 日
編集済み: Walter Roberson 2021 年 4 月 17 日
if ~isequal(transpose(ValueOfd), m)
disp("A is not diagonalizable")
else
disp("A is diagonalizable")
end
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 17 日
Remember isequal will not forgive floating-point round off differences.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWord games についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by