SET_THEORY
MATLAB Commands for Set Operations
SET_THEORY,
a MATLAB library which
demonstrates how set-theoretic operations can be carried out,
primarily using built-in MATLAB commands.
We assume that a set is represented by a strictly ascending sequence
of positive integers. We might think of a universal set U = 1 : N
in cases where all our subsets will have elements between 1 and N.
Set theoretic operations include
-
definition using a numeric property: A = find ( mod ( U, 3 ) = 1 );
-
definition using an explicit list: A = [ 1, 3, 8];
-
unique: creating a set from the unique elements of a list:
A = unique ( [ 1, 3, 8, 3, 3, 1, 7, 3, 1, 1 ] );
-
union: C = union ( A, B );
-
intersection: C = intersect ( A, B );
-
symmetric difference: C = setxor ( A, B );
-
complement with respect to the universal set: B = setdiff ( U, A );
-
complement with respect to another set: C = setdiff ( B, A );
-
cardinality: n = length ( A );
-
membership: true/false = ismember ( a, A );
-
subset: true/false = ismember ( B, A );
-
addition of one element: A = unique ( [ A; a ] );
-
deletion of one element: A = setxor ( A, a );
-
indexing one element: i = find ( A == a );
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
SET_THEORY is available in
a C version and
a C++ version and
a FORTRAN90 version and
a MATLAB version.
Related Data and Programs:
COMBO,
a MATLAB library which
handles combinatorial problems, by Kreher and Stinson;
set_theory_test
SUBSET,
a MATLAB library which
ranks, unranks, and generates random subsets, combinations, permutations, and so on;
Reference:
-
Charles Pinter,
Set Theory,
Addison-Wesley, 1971,
LC: QA248.P55.
Source Code:
Last revised on 12 March 2019.