Accelerating the pace of engineering and science

# solvelib::getElement

Get one element of a set

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```solvelib::getElement(S, <Random>)
```

## Description

solvelib::getElement(S) returns an element of S.

S can be a set of any type; see solve for an overview of all sets.

solvelib::getElement returns the value FAIL if:

• S is the empty set

• the solver cannot find any element of the set due to the solver's limitations

• the solver cannot compute the first element of a set. You can use the Random option to check a random element of a set instead of the first element

• the answer depends on a case analysis on some parameter

With the option Random, the probability to get any particular element of a set is:

• Roughly equal for the elements of a finite set

• Proportional to the multiplicities for the elements of a finite multiset of type Dom::Multiset

• Unspecified for the elements of an infinite set. Practically, the same result does not occur twice for infinite sets.

## Examples

### Example 1

If S is a finite set, the solver returns just one of the elements:

`solvelib::getElement({2, 7, a})`

### Example 2

For image sets, the solver replaces every parameter by a constant:

`S:=Dom::ImageSet(k*PI, k, solvelib::BasicSet(Dom::Integer))`

`solvelib::getElement(S)`

### Example 3

If the set is empty, the solver cannot find any element:

`solvelib::getElement({})`

solvelib::getElement might fail to find an element of a set although that set is not empty.

`solvelib::getElement(solve(exp(x) + cos(x) = x^2,x))`

### Example 4

Without the option Random, solvelib::getElement always produces the same result for a set:

`solvelib::getElement({\$1..5}) \$i=1..5`

With the option Random, the returned element varies randomly from call to call:

`solvelib::getElement({\$1..5}, Random) \$i=1..15`

The distribution of the returned values is close to the uniform distribution. For multisets, the multiplicity of elements is taken into account:

`solvelib::getElement(Dom::Multiset(1\$4, 2\$2), Random) \$i=1..18`

### Example 5

For the following set parametrized by integers, the solver fails to find an element. This is because the solver tries only the first parameter-value pair k = 0 for which the result is undefined. After that the solver does not try any other parameter-value pairs:

`solvelib::getElement(1/Z_)`

For the sets with the undefined first element, you can get the result calling the solver with the option Random:

`solvelib::getElement(1/Z_, Random)`

## Parameters

 S Any set

## Options

 Random Returns a random element of a set. Without this option, solvelib::getElement(S) always returns the same element.

## Return Values

solvelib::getElement returns a MuPAD® object representing an element of S, or FAIL if no element could be determined.