## Unit1.3.4The axpy operation

###### Homework1.3.4.1.

Compute

\begin{equation*} (-2) \left( \begin{array}{r} 2 \\ -1 \\ 3 \end{array} \right) + \left( \begin{array}{r} 2 \\ 1 \\ 0 \end{array} \right) \end{equation*}
Solution
\begin{equation*} \begin{array}{rcl} (-2) \left( \begin{array}{r} 2 \\ -1 \\ 3 \end{array} \right) + \left( \begin{array}{r} 2 \\ 1 \\ 0 \end{array} \right) = \left( \begin{array}{r} (-2) \times (2) \\ (-2) \times (-1) \\ (-2) \times (3) \end{array} \right) + \left( \begin{array}{r} 2 \\ 1 \\ 0 \end{array} \right)\\ \amp = \amp \left( \begin{array}{r} (-2) \times (2) + 2 \\ (-2) \times (-1) +1 \\ (-2) \times (3) +0 \end{array} \right) = \left( \begin{array}{r} -2 \\ 3 \\ -6 \end{array} \right) \end{array} \end{equation*}

Given a scalar, $\alpha \text{,}$ and two vectors, $x$ and $y \text{,}$ of size $n$ with elements

\begin{equation*} x = \left( \begin{array}{c c c c} \chi_0 \\ \chi_1 \\ \vdots \\ \chi_{n-1} \end{array} \right) \quad \mbox{and} \quad y = \left( \begin{array}{c c c c} \psi_0 \\ \psi_1 \\ \vdots \\ \psi_{n-1} \end{array} \right), \end{equation*}

the scaled vector addition (axpy) operation is given by

\begin{equation*} y := \alpha x + y \end{equation*}

which in terms of the elements of the vectors equals

\begin{equation*} \begin{array}{rcl} \left( \begin{array}{c c c c} \psi_0 \\ \psi_1 \\ \vdots \\ \psi_{n-1} \end{array} \right) \amp:=\amp \alpha \left( \begin{array}{c c c c} \chi_0 \\ \chi_1 \\ \vdots \\ \chi_{n-1} \end{array} \right) + \left( \begin{array}{c c c c} \psi_0 \\ \psi_1 \\ \vdots \\ \psi_{n-1} \end{array} \right) \\ \amp=\amp \left( \begin{array}{c c c c} \alpha \chi_0 \\ \alpha \chi_1 \\ \vdots \\ \alpha \chi_{n-1} \end{array} \right) + \left( \begin{array}{c c c c} \psi_0 \\ \psi_1 \\ \vdots \\ \psi_{n-1} \end{array} \right) = \left( \begin{array}{c c c c} \alpha \chi_0 + \psi_0 \\ \alpha \chi_1 + \psi_1 \\ \vdots \\ \alpha \chi_{n-1} + \psi_{n-1} \end{array} \right). \end{array} \end{equation*}

The name axpy comes from the fact that in Fortran 77 only six characters and numbers could be used to designate the names of variables and functions. The operation $\alpha x + y$ can be read out loud as "scalar alpha times x plus y" which yields the acronym axpy.

###### Homework1.3.4.2.

An outline for a routine that implements the axpy operation is given by

#define chi( i ) x[ (i)*incx ]   // map chi( i ) to array x
#define psi( i ) y[ (i)*incy ]   // map psi( i ) to array y

void Axpy( int n, double alpha, double *x, int incx, double *y, int incy )
{
for ( int i=0; i<n; i++ )
psi(i)  +=
}


Complete the routine and test the implementation by using it in the next unit.