Vector and Matrix Construction
cmatrix-
sparse_matrix(x, v, m)-
x– A matrix -
v– A column vector of values to add to elements of x -
m– A matrix of integers
-
# 1. Fill x with all zeros.
x[,] = 0
# 2. Add elements in v to elements of x, according to the indices in m.
for (int k=0; i<n; i++)
x[m[k,0], m[k,1]] += v[m[k,2], 0]
# 3. Return x.
x