<< deck_tarot Sets element_of >>

Scilab Scholar module for schools >> Sets > define_set

define_set

defines and constructs a set

Calling sequence

setA = define_set(e1,e2,...)

Arguments

e1, e2,...

character strings or vectors of character strings

setA

set

Description

The function define_set defines and constructs a set. e1, e2,... are character strings or vectors of character strings. The set then contains all the character strings e1, e2,... A set is not ordered and does not contain duplicate elements. For example {a,b,c} and {b,a,c,a} represent the same set. When a set is created, duplicate elements are suppress, and for convenience, its elements are arranged in alphabetical order.

Note that define_set() creates an empty set.

It is possible to assign values to the elements of a set. This enables one, for example, to have sets of coins, tickets or playing cards with values. For this, the value is given by placing them in parentheses at the end of the name of an element. For example to create a set of 3 coins called "a", "b" and "c", with values 1 euro, 1 euro and 2 euros, one writes :

set1=define_set("a(1)","b(1)","c(2)").

The function value returns the vector of values for the elements of a set, allowing numerical calculations to be done with them (see value).

To change or remove an item from a set, use parentheses as with a vector. We put the rank of the element in parentheses, knowing that the elements were stored automatically in alphabetical order.

To obtain the size of a set use the function size.

To compare two sets use the usual comparison operator ==.

Examples

set1=define_set("b","a","c","a")
size(set1)
set2=define_set("a","b","c")
set1==set2
setA=define_set("a","b",string(1:5))
// note the elements are arranged in alphabetical order
define_set(string(1:10))

See Also

<< deck_tarot Sets element_of >>