Why is MATLAB giving false output for A and B being equal?

  • Context: MATLAB 
  • Thread starter Thread starter stihl29
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The MATLAB code provided demonstrates that the orthogonal matrix A and its inverse B are not considered equal due to numerical approximation errors inherent in floating-point calculations. Specifically, the orthogonalization of the matrix A results in a minor discrepancy when compared to its inverse, leading to the output 'no match'. The difference is quantified as approximately 1.0e-015, confirming that A and B are not strictly equal, despite their theoretical relationship.

PREREQUISITES
  • Understanding of MATLAB syntax and operations
  • Familiarity with matrix operations, specifically orthogonalization and inversion
  • Knowledge of floating-point arithmetic and numerical precision issues
  • Experience with MATLAB's built-in functions such as orth and inv
NEXT STEPS
  • Explore MATLAB's numerical precision and how it affects matrix comparisons
  • Learn about alternative methods for comparing floating-point matrices in MATLAB
  • Investigate the implications of using isequal versus == for matrix equality
  • Study the behavior of orthogonal matrices and their properties in linear algebra
USEFUL FOR

MATLAB users, data scientists, and engineers who work with numerical methods and require a deeper understanding of matrix operations and their implications in computational environments.

stihl29
Messages
24
Reaction score
0
i have this code

A = [2 -2;-2 -1];
A=orth(A);
B=inv(A);
if A==B
disp('match');
else
disp('no match');
end

they are the same, but i always get the output 'no match'

any ideas?
 
Physics news on Phys.org
Technically A is not equal to B because the inverse algorithm gives only an approximation.

To see this,

Code:
>> orth([2 -2;-2 -1]) - inv(orth([2 -2;-2 -1]))
ans =
  1.0e-015 *
   0.888178419700125  -0.444089209850063
  -0.388578058618805  -0.777156117237609

So your expression is being analysed as false.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K