Checking whether two complex matrices are equal

For matrix A=[3 -3 4;2 3 4;0 -1 1]; I have to prove that eigenvalues of A^2 is equal to square of eigenvalues of A. After obtaining eigenvales I used == to compare results. Both matrix were same but using == gives me result [0 1 1;1 0 1; 1 1 0]. Why?

 采纳的回答

You can't rely on floating point calculations to give exact results. See this link:
You need to use tolerances for these types of floating point comparisons. E.g.,
>> A = [3 -3 4;2 3 4;0 -1 1];
>> A2 = A*A;
>> eig(A).^2
ans =
-0.999999999999988 +18.973665961010287i
-0.999999999999988 -18.973665961010287i
1.000000000000000 + 0.000000000000000i
>> eig(A2)
ans =
-1.000000000000000 +18.973665961010266i
-1.000000000000000 -18.973665961010266i
1.000000000000001 + 0.000000000000000i
>> eig(A).^2 == eig(A2)
ans =
3×1 logical array
0
0
0
>> abs(eig(A).^2 - eig(A2)) < 1e-10
ans =
3×1 logical array
1
1
1
But, this isn't really a "proof" of course ... just a demonstration within numerical tolerances.
A proof for this case would be to use the Symbolic Toolbox. E.g., start with this:
As = sym(A);
And then work everything with As instead of A. Then see how the results compare ... (hint: you may need to use the simplify( ) function and you may need to reorder the eigenvalues before the comparison)
A general proof for an arbitraty matrix A would be starting with A*x = lambda*x on paper, multiplying both sides by A, and then seeing what you get as a result using hand calculations and simplifying.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by