-
Notifications
You must be signed in to change notification settings - Fork 31
/
difer.m
84 lines (80 loc) · 2.02 KB
/
difer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function varargout=difer(V,tolex,sev,goods)
% DIFER(V,tolex,sev,goods)
% a=DIFER(V,tolex,sev,goods)
%
% Checks if the sum(abs(V(:))) exceeds 10^(-tolex)
%
% INPUT:
%
% V Vector or matrix values (NOT symbolic ones!)
% tolex Tolerance exponent (default: 10 for 1e-10)
% sev 0 produces WARNING upon failure [default]
% 1 produces ERROR upon failure
% 2 invokes KEYBOARD upon failure
% goods A string with an uplifting message (if NaN, no message)
% displayed in case it's all good
%
% OUTPUT (optional)
%
% a 1 (logical) if V is bigger than "zero"
% 0 (logical) if it isn't
% but remember if you request output there's no message and no
% action modulated by "sev"
%
% SEE ALSO:
%
% DIFERM, ISEQUAL
%
% Last modified by fjsimons-at-alum.mit.edu, 09/23/2023
% Which one is the calling program?
[path,name,ext]=star69;
% Check in the calling routine that the incoming terms are not below
% machine precision even before they are being compared!
% disp('should make one called differr for relative comparisons')
defval('V',0)
defval('tolex',10)
defval('sev',0)
defval('goods',...
sprintf('%s Check passed to tolerance E%i',...
upper(name),-tolex))
if ~isstruct(V) & ~strcmp(class(V),'sym')
sabs=sum(abs(V(:)));
else
error('No support for the struct/sym class')
end
% Make this explicitly equal to 1 if not symbolic variables will falsely test
if ~isnan(sabs)
if sabs>10^(-tolex)
mesg=sprintf('sum(abs(%s)) exceeds 0 by %8.3e',inputname(1),sabs);
switch sev
case 0
if nargout==0
warning(mesg)
else
varargout{1}=logical(1);
end
case 1
if nargout==0
error(mesg)
else
varargout{1}=logical(1);
end
case 2
if nargout==0
keyboard
else
varargout{1}=logical(1);
end
end
else
if nargout~=0
varargout{1}=logical(0);
else
if ~isnan(goods)
disp(sprintf(goods,-tolex))
end
end
end
else
error('Comparison contains NaNs or is empty')
end