Vector and Matrix Construction
c
matrix
-
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.
[,] = 0
x
# 2. Add elements in v to elements of x, according to the indices in m.
for (int k=0; i<n; i++)
[m[k,0], m[k,1]] += v[m[k,2], 0]
x
# 3. Return x.
x