the following command to Octave
Q = sparse ([2 3 7], [1 2 7] [1 1 1], 7.7)generates a sparse matrix of size 7x7 in which only three elements are different from 0 (and only these three elements are actually stored): the element in position (2.1), one in position (3.2) and the position (7.7), all assume the value 1.
Of the five parameters of the command, in fact, the first carrier is the ordered set of indices of the row, the second is the sorted array of indices and the third column is the vector, yet ordered, values. The non-zero values \u200b\u200bcan be more easily identified by superimposing the three vectors:
row [2 3 7]
column [1 2 7]
value [1 1 1] The
fourth and fifth parameters are the overall size of the matrix, in the absence of these two parameters, Octave assumes the array size as the two highest indices for row and column.
If two different values \u200b\u200bfor the same element are set, by default the two values \u200b\u200bare added. If you want the last set value is the only correct then you must use a sixth argument, like this:
Q = sparse ([2 3 7 2], [1 2 7 1], [1 1 1 2], 7.7, "unique")that, in this case, means that the value associated with the position (2.1) is equal to 2.
0 comments:
Post a Comment