title: Matrix vector multiplication CCS c++
body: <p>I am trying to multiply a matrix and a vector with the matrix in <a href="http://netlib.org/linalg/html_templates/node92.html" rel="nofollow">Compressed Column Storage</a>. The matrix is :</p>
  
  <pre><code>0   3   0   
  4   0   0   
  2   0   0
  </code></pre>
  
  <p>here is the CCS form:</p>
  
  <pre><code>[ 4 2 3 ]
  [ 2 3 1 ]
  [ 1 3 4 4 ]
  </code></pre>
  
  <p>The vector is:</p>
  
  <pre><code>[ 1 3 4 ]
  </code></pre>
  
  <p>So the product should be</p>
  
  <pre><code>[ 9 4 2 ]
  </code></pre>
  
  <p>Here is the function I am trying to create</p>
  
  <pre><code>vector&lt;int&gt; multiply(vector&lt;int&gt; val,vector&lt;int&gt; col,vector&lt;int&gt; row,vector&lt;int&gt; v, int r){
  
      vector&lt;int&gt; x(v.size());
      for (int j=0; j&lt;r; j++) {
          for (int i=col[j]-1; i&lt;col[j+1]-1; i++) {
              cout&lt;&lt;"\n"&lt;&lt;val[i]&lt;&lt;"*"&lt;&lt;v[j]&lt;&lt;"\n";
              x[j]+= val[i]*v[j];
          }
      }
      return x;
  }
  </code></pre>
  
  <p>But this returns</p>
  
  <pre><code>[ 6 9 0 ]
  </code></pre>
  
  <p>This is the closest I've gotten to the real solution, how can I fix this?</p>