The same old problem... your mind is set to indeces starting at 1 not 0. See the error below, my comments are hash-marked: for ( i =0; i < (rows(invec)-1); ++i ) #### so i goes from 1 to 9 if you have 10 rows ##### { if ( i == 0 ) { print("i = ",i,"\n"); outvec[i][0] = invec[i+1][0] + invec[i][0]; #### Here, you will get invec[ ### 10 ### ][0] which is out of range ##### } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%