Checking of equality for two matrices

조회 수: 354 (최근 30일)
Ian Thean
Ian Thean 2019년 10월 8일
댓글: the cyclist 2019년 10월 8일
Hi I have trouble coming out the code to find the equality of two matrices. I have to test and display that the matrices are equal. I am trying to include 'if' statement in as well.
Here is the question:
Calculate AxB and BxA and test if AB = BA.
Thanks!
  댓글 수: 5
the cyclist
the cyclist 2019년 10월 8일
An advantage of using isequal(A,B) over A==B is that if A and B are different sizes (e.g. 4x4 vs. 3x3), then A==B will throw an error because of the dimension mismatch, but isequal will return a result.
This may not be important in your specific case, but could be in general.
the cyclist
the cyclist 2019년 10월 8일
Also, I think you mean to check isequal(A*B,B*A), not just isequal(A,B).
Be aware of the accuracy of floating-point numbers for exact equality check.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2019년 10월 8일
The difference between the isequal function and the == operator is that the second will work element by element. That means that isequal will tell you if two matrices are the exact same, while == will test all elements individually.
One golden tip: always make sure your input to if or while is a scalar, not a logical array. Array input tend to do something different from what you might mean.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by