forked from gnu-octave/symbolic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interval.m
94 lines (81 loc) · 2.28 KB
/
interval.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
85
86
87
88
89
90
91
92
93
94
%% Copyright (C) 2016 Colin B. Macdonald and Lagu
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.
%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@interval interval (@var{A}, @var{B})
%% @defmethodx @@interval interval (@var{A}, @var{B}, @var{lopen})
%% @defmethodx @@interval interval (@var{A}, @var{B}, @var{lopen}, @var{ropen})
%% Return an interval.
%%
%% Examples:
%% @example
%% @group
%% interval(sym(0), sym(1))
%% @result{} (sym) [0, 1]
%% interval(sym(0), 1, true, true)
%% @result{} (sym) (0, 1)
%% interval(sym(0), 1, false, true)
%% @result{} (sym) [0, 1)
%% @end group
%% @end example
%%
%% Intervals can be degenerate:
%% @example
%% @group
%% interval(sym(1), 1)
%% @result{} (sym) @{1@}
%% interval(sym(2), 1)
%% @result{} (sym) ∅
%% @end group
%% @end example
%%
%% @seealso{finiteset, @@sym/union, @@sym/intersect, @@sym/setdiff, @@sym/unique, @@sym/ismember}
%% @end defmethod
function I = interval(varargin)
if (nargin < 2 || nargin > 4)
print_usage();
end
lhs = sym(varargin{1});
rhs = sym(varargin{2});
if (nargin == 2)
bls = false;
brs = false;
end
if (nargin == 3)
bls = logical(varargin{3});
brs = false;
end
if (nargin == 4)
bls = logical(varargin{3});
brs = logical(varargin{4});
end
expr = python_cmd ('return Interval(*_ins),', lhs, rhs, bls, brs);
I.vars = [];
I = class(I, 'interval', expr);
superiorto ('sym');
end
%!test
%! a = interval(sym(1), 2);
%! assert (isa (a, 'sym'))
%!test
%! % some set subtraction
%! a = interval(sym(0), 4);
%! b = interval(sym(0), 1);
%! c = interval(sym(1), 4, true);
%! q = a - b;
%! assert (isequal( q, c))