Matrix

  1. k-th element of A is A[k]

    The matrix indexing operator is []. For example, the second element of x is x[2] and the element of A at row 3 and column 5 is A[3,5].

  2. A(x) means A * x

    A(x) is evaluated as A * x. That is, matrix A is used as a linear function (In order for A(x) to work, the number of rows of x should match the number of columns of A). A matrix is a function and can be used anywhere a function is expected.

  3. Row major storage format

    Dense matrices are stored in row major order. Thus, if A is an $ m\times n$ matrix, A[j, k] is equivalent to A[j * n + k].

  4. The last element of A is A[$]

    The last element of A is A[$], not A[end].

    The last element on the third row of A is A[3, $], not A[3, end].

  5. rand(n) is the same as rand(n, 1) not rand(n, n)

    rand(n), zeros(n), and ones(n) return $ n\times 1$ matrices in stead of $ n\times n$ square matrices. To obtain square matrices, one has to use calls like rand(n, n)

  6. Matrix Storage Format

    Dense matrices are stored in row major order, as opposed to the column major order used in Matlab. This means that each row of a matrix is usually stored in a contiguous memory block, and the rows are stored one after another.

    Row major and column major are equivalent when elements of A are accessed by using two indices like in A[i, j]. However, expression with a single index behaves differently in row major and column major. For example, if A is a matrix of 5 rows and 5 columns, then A[1], ...,A[5] are the five elements in the first row, while A[6], ..., A[10] refer to the five elements in the second row.

  7. More powerful Indexing Expressions

    Semicolons and backslashes can be used in indexing expressions. For examples

oz 2009-12-22