Work@Microsoft    Live@Seattle

Matrix – Vector Multiplication

Rate this post

The general formula for a matrix-vector product is

  • The number of columns in A (n) has to equal the number of components in the vector x (n).
  • The number of rows in A (m) determines the number of components in the result Ax.

For example,

Here is the C++ implementation of matrix – vector multiplication.  The complete source code of CMatrix and CVector can be downloaded from here.

CMatrix::operator*(const CVector & v) const
    assert(v.Length() == _columns);

    T * data = new T[_rows];
    if (data == NULL)

    for (int i = 0; i < _rows; i++)
        data[i] = 0;
        for (int j = 0; j < _columns; j++)
            data[i] += get(i, j)*v[j];

    return CVector(_rows, data, true);

Leave a Comment

Your email address will not be published. Required fields are marked *