isequal functions is not working, what am I doing wrong?

23 ビュー (過去 30 日間)
Sandy
Sandy 2015 年 12 月 2 日
編集済み: Kirby Fears 2015 年 12 月 11 日
I have the following code, the result tells me it's false. What am I ding worng?
A = [(1/sqrt(3)), (-1/sqrt(2)), (1/sqrt(6)); (1/sqrt(3)), 0, (-2/sqrt(6));(1/sqrt(3)), (1/sqrt(2)), (1/sqrt(6))];
A_T = A';
A_1 = (A^-1);
tf = isequal(A_T,A_1)

採用された回答

Kirby Fears
Kirby Fears 2015 年 12 月 2 日
編集済み: Kirby Fears 2015 年 12 月 11 日
In your Command Window, type this:
format long
A_T
A_1
You'll see elements of A_T and A_1 are essentially the same, but the last digit may not be exactly the same.
You're using two different methods on A that have the same theoretical answer (A' and A^-1). Both calculations are subject to machine error since they only track 64 bits of information. Since A' and A^-1 use different algebra to arrive at the same answer, they end up with slightly different 64-bit rounded answers.
You can check for equality up to a given threshold like this:
threshold = 1e-10; % set your level of accuracy for "equality"
tf = all(abs(A_T(:) - A_1(:))<=threshold);
  1 件のコメント
Sandy
Sandy 2015 年 12 月 2 日
Perfect! Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by