However, B+C and C*A produce error messages. Hence calculate after the prompt D=2*A-B, F=A*B, G=A*C, Asq=A^2. Providing they have compatible shapes they can be multiplied using the established rules for matrix multiplication. Providing matrices have the same shape they can be added or subtracted. Hence A(:,2) is column number 2 in the matrix A while is the first row of B. The comma separates the row number(s) from the column number(s).Ī single colon “:” before the comma means “take all rows”, whereas a single colon after the comma means “take all columns”.
The element A(i,j) is in the i th row and j th column.
For example, run the following M-file mat.m: To construct a matrix with m rows and n columns (called an “m by n matrix”, written m×n matrix), each row in the array ends with a semicolon. But you are aware that a rectangular array represents a matrix and a single array column represents a column vector. Each array that was discussed in Section 4 was, in effect, a row vector or row matrix.