!
FLUENT Verification ProjectI've created a few basic demonstrations to accompany my introductory notes on Set Theory. They are attached to this link as a zip file.
To run the demonstrations, you can extract the zip file within your user's MATLAB directory, or you can use
Matlab Online and get a copy of the files
at this link. In Matlab, open the script called "basic_operations.m" and take a moment to examine it. I'm using Matlab's "cell arrays" to illustrate set concepts. A cell array is declared using curly braces, like this:
U = {'Hao'
'Zhen'
'Mohammad'
'Riley'
'Lukas'
'Tom'
};
Click the green "Run" button at the top of the Matlab window. It may ask if you want to change folders; say Yes. The script will print out a succession of set examples, pausing between each one. You need to press return after each example.
When the '>>' prompt appears in the Command Window, the script is done. At this point you can experiment with some of the set commands. Here are some simple examples:
U = union(U,{'Curtis'})
-- add Curtis to the UniverseU = setdiff(U,{'Curtis'})
-- remove Curtis from the Universesetdiff(U,S)
-- complement of S
(undergrads)X = {P S G}
-- set-of-sets containing P
(professors), S
(undergrads), and G
(grads)
There are two other scripts for demonstrating Power Sets. The function
powerset(S)
uses a recursive method to construct the Power Set of S. The function
printset
prints the contents of a Power Set in a readable format. Example usage:
PS = powerset({'a' 'b'});
printset(PS)
The
printset
function can also be used to display a set-of-sets like the example
X
above.
While a full Matlab tutorial is beyond the scope of these demos, there are a couple of particularly useful notes:
- Confirm the size of a set using the
numel
function (short for "number of elements"), e.g. numel(PS)
. - Extract individual elements using curly braces, e.g.
U{1}
returns 'Hao'
. The elements are indexed starting from 1. Also use curly braces to extract subsets from a set-of-sets, e.g. X{1}
. - Cell arrays allow duplicate elements, but true sets do not. Use the
unique
function to eliminate duplicates, e.g. unique({'a' 'a' 'b'})
returns {'a' 'b'}
.
A couple of exercises:
- Using only complements and unions of subsets like S and P, confirm that you can obtain intersections of those sets.
- Study the set-of-sets {S,P,G,F}. Is this set closed under unions and complements? If not, what needs to be added for it to be usable as a set algebra?
- Can you make a set-of-sets that is closed under unions but not complements?
#
matlab #
SetTheory