VectorΒΆ

The Vector domain is used for storing data in a one-dimensional indexed data structure. A vector is a homogeneous data structure in that all the components of the vector must belong to the same FriCAS domain. Each vector has a fixed length specified by the user; vectors are not extensible. This domain is similar to the OneDimensionalArray domain, except that when the components of a Vector belong to a Ring, arithmetic operations are provided.

As with the OneDimensionalArray domain, a Vector can be created by calling the operation new, its components can be accessed by calling the operations elt and qelt, and its components can be reset by calling the operations setelt and qsetelt.

This creates a vector of integers of length 5 all of whose components are 12.

u : VECTOR INT := new(5,12)
  [12,12,12,12,12]
                              Type: Vector Integer

This is how you create a vector from a list of its components.

v : VECTOR INT := vector([1,2,3,4,5])
  [1,2,3,4,5]
                              Type: Vector Integer

Indexing for vectors begins at 1. The last element has index equal to the length of the vector, which is computed by #.

#(v)
   5
                               Type: PositiveInteger

This is the standard way to use elt to extract an element. Functionally, it is the same as if you had typed elt(v,2).

v.2
  2
                              Type: PositiveInteger

This is the standard way to use setelt to change an element. It is the same as if you had typed setelt(v,3,99).

v.3 := 99
  99
                              Type: PositiveInteger

Now look at v to see the change. You can use qelt and qsetelt (instead of elt and setelt, respectively) but only when you know that the index is within the valid range.

v
  [1,2,99,4,5]
                              Type: Vector Integer

When the components belong to a Ring, FriCAS provides arithmetic operations for Vector. These include left and right scalar multiplication.

5 * v
  [5,10,495,20,25]
                              Type: Vector Integer

v * 7
  [7,14,693,28,35]
                              Type: Vector Integer

w : VECTOR INT := vector([2,3,4,5,6])
  [2,3,4,5,6]
                              Type: Vector Integer

Addition and subtraction are also available.

v + w
  [3,5,103,9,11]
                              Type: Vector Integer

Of course, when adding or subtracting, the two vectors must have the same length or an error message is displayed.

v - w
  [- 1,- 1,95,- 1,- 1]
                              Type: Vector Integer

See Also:

  • )help List
  • )help Matrix
  • )help OneDimensionalArray
  • )help Set
  • )help Table
  • )help TwoDimensionalArray
  • )show Vector

Table Of Contents

This Page