## `linalg::angle` -- The angle between two vectors

#### Introduction

`linalg::angle``(u,v)` computes the angle phi between the two vectors `u` and `v`, defined by

    phi = arccos(u*v / (|u||v|)).

#### Call(s)

`linalg::angle(u, v)`

#### Parameters

`u, v` | - | vectors of the same dimension; a vector is a n x 1 or 1 x n matrix of a domain of category `Cat::Matrix`

#### Returns

an arithmetical expression.

#### Related Functions

`arccos`, `linalg::scalarProduct`, `linalg::vecdim`

#### Details

- For the equation

      phi = arccos(u*v / (|u||v|))

  the product u*v denotes the scalar product of two vectors given by `linalg::scalarProduct`, and | | the 2-norm of a vector, i.e., |u|=sqrt( u*u ).
- `linalg::angle` does not check if the computation is defined in the corresponding component ring. This can lead to an error message, as shown in Example 2.
- The following relationship between the angle between u and v and the angle between u and -v holds: phi(u,v) = PI - phi(u,-v).
- An error message is returned if the vectors are not defined over the same component ring.

#### Example 1

We compute the angle between the two vectors [2,5] and [-3,3]:

    >> phi := linalg::angle(
         matrix([2, 5]), matrix([-3, 3])
       )

                                     /   1/2   1/2 \
                                     | 18    29    |
                               arccos| ----------- |
                                     \     58      /

We use the function `float` to get a floating-point approximation of this number:

    >> float(phi)

                                    1.165904541

We give two further examples:

    >> linalg::angle(
         matrix([1, -1]), matrix([1, 1])
       )

                                        PI
                                        --
                                        2

    >> linalg::angle(
         matrix([1, 1]), matrix([-1, -1])
       )

                                        PI

#### Example 2

`linalg::angle` does not check whether the term u*v / (|u||v|) is defined in the corresponding component ring.

As an example, we try to compute the angle between two vectors with components in Z7:

    >> MatZ7 := Dom::Matrix(Dom::IntegerMod(7))

                          Dom::Matrix(Dom::IntegerMod(7))

The following call leads to an error because the 2-norm cannot be computed:

    >> linalg::angle(MatZ7([1, 1]), MatZ7([-1, -1]))

          Error: no integer exponent [(Dom::IntegerMod(7))::_power]

Note that the domain `Dom::IntegerMod(7)` does not implement the square root of an element, therefore in MuPAD you cannot compute the angle of any two vectors over Z7.

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