## `linalg::VectorOf` -- type specifier for vectors

#### Introduction

`linalg::VectorOf``(R, n)` is a type specifier for vectors with n components over the component ring R.

#### Call(s)

`linalg::VectorOf(R)`
`linalg::VectorOf(R, n)`

#### Parameters

`R` | - | the component ring: a library domain
`n` | - | a positive integer

#### Returns

a type expression of the domain type `Type`.

#### Related Functions

`testtype`

#### Details

- `linalg::VectorOf``(R)` is a type specifier representing all objects of a domain of category `Cat::Matrix` with component ring `R` and number of rows or number of columns equal to one.
- `linalg::VectorOf``(R,n)` is a type specifier representing all objects of a domain of category `Cat::Matrix` with component ring `R` and number of rows equal to `n` and number of columns equal to one, or vice versa.
- `linalg::VectorOf``(Type::AnyType,n)` is a type specifier representing all objects of a domain of category `Cat::Matrix` with an arbitrary component ring `R` and number of rows equal to `n` and number of columns equal to one, or vice versa.

#### Example 1

`linalg::VectorOf` can be used together with `testtype` to check whether a MuPAD object is a vector:

    >> MatZ := Dom::Matrix(Dom::Integer):
       v := MatZ([1, 0, -1])

                                     +-    -+
                                     |   1  |
                                     |      |
                                     |   0  |
                                     |      |
                                     |  -1  |
                                     +-    -+

The following yields `FALSE` because `v` is 3-dimensional vector:

    >> testtype(v, linalg::VectorOf(Dom::Integer, 4))

                                       FALSE

The following yields `FALSE` because `v` is defined over the integers:

    >> testtype(v, linalg::VectorOf(Dom::Rational))

                                       FALSE

Of course, `v` can be converted into a vector over the rationals, as shown by the following call:

    >> testtype(v, Dom::Matrix(Dom::Rational))

                                       TRUE

This shows that `testtype` in conjunction with `linalg::VectorOf``(R)` does not check whether an object can be converted into a vector over the specified component ring `R`. It checks only if the object is a vector whose component ring is `R`.

The following test returns `TRUE` because `v` is a 3-dimensional vector:

    >> testtype(v, linalg::VectorOf(Type::AnyType, 3))

                                       TRUE

#### Example 2

`linalg::VectorOf` can also be used for checking parameters of procedures. The following procedure computes the orthogonal complement of a 2-dimensional vector:

    >> orth := proc(v:linalg::VectorOf(Type::AnyType, 2))
       begin
           [v[1], v[2]] := [-v[2],v[1]];
           return(v)
       end:

       u := matrix([[1, 2]]); u_ := orth(u)

                                     +-    -+
                                     | 1, 2 |
                                     +-    -+

                                     +-     -+
                                     | -2, 1 |
                                     +-     -+

Calling the procedure `orth` with an invalid parameter leads to an error message:

    >> orth([1, 2])

          Error: Wrong type of 1. argument (type 'slot(Type, VectorOf)(T\
          ype::AnyType, 2)' expected,
                 got argument '[1, 2]');
          during evaluation of 'orth'

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000