Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@math/isequal.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % ISEQUAL test if two matrices are equal to within the given tolerance. | |
2 % | |
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4 % | |
5 % DESCRIPTION: ISEQUAL test if two matrices are equal to within the given | |
6 % tolerance. | |
7 % | |
8 % CALL: result = isequal(m1, m2) | |
9 % result = isequal(m1, m2, tol) | |
10 % | |
11 % INPUTS: m1 - a matrix of real or complex values | |
12 % m2 - a matrix of real or complex values | |
13 % tol - the tolerance to test against [default: 1e-14] | |
14 % | |
15 % OUTPUTS: result - true or false | |
16 % | |
17 % VERSION: $Id: isequal.m,v 1.8 2010/11/19 12:40:13 ingo Exp $ | |
18 % | |
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
20 function res = isequal(varargin) | |
21 | |
22 % Check size of the input numbers | |
23 if ~all(size(varargin{1}) == size(varargin{2})) || ... | |
24 ~(isnumeric(varargin{1}) || islogical(varargin{1})) || ... | |
25 ~(isnumeric(varargin{2}) || islogical(varargin{2})) | |
26 res = false; | |
27 return | |
28 end | |
29 | |
30 m1 = double(varargin{1}); | |
31 m2 = double(varargin{2}); | |
32 | |
33 r = m1./m2; | |
34 | |
35 if nargin > 2 && ~isempty(varargin{3}) | |
36 tol = varargin{3}; | |
37 else | |
38 tol = 1e-14; | |
39 end | |
40 | |
41 maxAbsDiff = abs(max(1-abs(r))); | |
42 minAbsDiff = abs(min(1-abs(r))); | |
43 maxAngleDiff = max(abs(angle(r))); | |
44 minAngleDiff = min(abs(angle(r))); | |
45 | |
46 maxAbsDiff(isnan(maxAbsDiff))=0; | |
47 minAbsDiff(isnan(minAbsDiff))=0; | |
48 maxAngleDiff(isnan(maxAngleDiff))=0; | |
49 minAngleDiff(isnan(minAngleDiff))=0; | |
50 | |
51 if all([maxAbsDiff < tol,... | |
52 minAbsDiff < tol, ... | |
53 maxAngleDiff < tol, ... | |
54 minAngleDiff < tol]) | |
55 | |
56 res = true; | |
57 else | |
58 res = false; | |
59 end | |
60 | |
61 end |