F06 Chapter Contents
F06 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF06FAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F06FAF computes the cosine of the angle between two real vectors.

## 2  Specification

 FUNCTION F06FAF ( N, J, TOLX, X, INCX, TOLY, Y, INCY)
 REAL (KIND=nag_wp) F06FAF
 INTEGER N, J, INCX, INCY REAL (KIND=nag_wp) TOLX, X(*), TOLY, Y(*)

## 3  Description

F06FAF returns, via the function name, the cosine of the angle between two $n$-element real vectors $x$ and $y$, given by the expression
 $xTy x2y2 .$
If $1\le j\le n$, $y$ is taken to be the unit vector ${e}_{j}$, in which case the array Y is not referenced.
If ${‖x‖}_{2}\le \mathit{tolx}$, the routine returns $2.0$; if ${‖x‖}_{2}>\mathit{tolx}$ but ${‖y‖}_{2}\le \mathit{tol}y$, the routine returns $-2.0$; otherwise the value returned is in the range $\left(-1.0,1.0\right)$.

None.

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of elements in $x$ and $y$.
2:     J – INTEGERInput
On entry: if the vector $y$ is supplied in Y, J should be set to $0$. Otherwise, J specifies the index $j$ of the unit vector ${e}_{j}$ to be used as $y$.
3:     TOLX – REAL (KIND=nag_wp)Input
On entry: the value $\mathit{tolx}$, used to determine whether ${‖x‖}_{2}$ is effectively zero.
If TOLX is negative, the value zero is used.
4:     X($*$) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array X must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,1+\left({\mathbf{N}}-1\right)×\left|{\mathbf{INCX}}\right|\right)$.
On entry: the $n$-element vector $x$.
If ${\mathbf{INCX}}>0$, ${x}_{\mathit{i}}$ must be stored in ${\mathbf{X}}\left(1+\left(\mathit{i}-1\right)×{\mathbf{INCX}}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
If ${\mathbf{INCX}}<0$, ${x}_{\mathit{i}}$ must be stored in ${\mathbf{X}}\left(1-\left({\mathbf{N}}-\mathit{i}\right)×{\mathbf{INCX}}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
Intermediate elements of X are not referenced.
5:     INCX – INTEGERInput
On entry: the increment in the subscripts of X between successive elements of $x$.
6:     TOLY – REAL (KIND=nag_wp)Input
On entry: the value $\mathit{toly}$, used to determine whether ${‖y‖}_{2}$ is effectively zero.
If TOLY is negative, the value zero is used.
7:     Y($*$) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array Y must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,1+\left({\mathbf{N}}-1\right)×\left|{\mathbf{INCY}}\right|\right)$.
On entry: if $1\le {\mathbf{J}}\le {\mathbf{N}}$, Y is not referenced. Otherwise, Y holds the vector $y$.
If ${\mathbf{INCY}}>0$, ${y}_{\mathit{i}}$ must be stored in ${\mathbf{Y}}\left(1+\left(\mathit{i}-1\right)×{\mathbf{INCY}}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
If ${\mathbf{INCY}}<0$, ${y}_{\mathit{i}}$ must be stored in ${\mathbf{Y}}\left(1-\left({\mathbf{N}}-\mathit{i}\right)×{\mathbf{INCY}}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
Intermediate elements of Y are not referenced.
8:     INCY – INTEGERInput
On entry: the increment in the subscripts of Y between successive elements of $y$.

None.

Not applicable.

None.

None.