-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from eminSerin/dev
NBS-Predict v1.0.0-beta.12-hotfix
- Loading branch information
Showing
5 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function isSymmetric = is_symmetric(matrix, tolerance) | ||
% IS_SYMMETRIC Checks if a given matrix is symmetric within a specified tolerance. | ||
% | ||
% Syntax: | ||
% isSymmetric = is_symmetric(matrix, tolerance) | ||
% | ||
% Input Arguments: | ||
% matrix - A square matrix to be checked for symmetry. | ||
% tolerance - A scalar value specifying the tolerance for the symmetry check. | ||
% If not provided, the default value is 1e-15. | ||
% | ||
% Output Argument: | ||
% isSymmetric - A logical value indicating whether the matrix is symmetric | ||
% within the specified tolerance. Returns true if the matrix | ||
% is symmetric and false otherwise. | ||
% | ||
% Example: | ||
% matrix = [1, 2; 2, 1]; | ||
% isSymmetric = is_symmetric(matrix, 1e-15); | ||
% | ||
% This will return true as the matrix is symmetric within the tolerance of 1e-15. | ||
% | ||
% Note: | ||
% The function first checks if the matrix is square. If not, it returns false. | ||
% Then it calculates the absolute difference between the matrix and its transpose. | ||
% If all elements in the difference matrix are within the tolerance, it returns true. | ||
% Otherwise, it returns false. | ||
% | ||
if nargin < 2 | ||
tolerance = 1e-15; | ||
if size(matrix, 1) ~= size(matrix, 2) | ||
isSymmetric = false; | ||
return; | ||
end | ||
|
||
% Calculate the difference between the matrix and its transpose | ||
diffMatrix = abs(matrix - matrix'); | ||
|
||
% Check if all elements in the difference matrix are within the tolerance | ||
isSymmetric = all(all(diffMatrix <= tolerance)); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters