Table of Contents

    Matrix Multiplication and Division in R Programming Language: Methods and Examples

    Matrix Multiplication and Division in R Programming Language: Methods and Examples

    Matrix Computations

    Various mathematical operations are performed on the matrices using the R operators. The result of the operation is also a matrix.

    The dimensions (number of rows and columns) should be same for the matrices involved in the operation.

    Matrix Multiplication & Division

     

    # Create two 2x3 matrices.
    matrix1

    When we execute the above code, it produces the following result −

    [,1] [,2] [,3]
    [1,]    3   -1    2
    [2,]    9    4    6
         [,1] [,2] [,3]
    [1,]    5    0    3
    [2,]    2    9    4
    Result of multiplication 
         [,1] [,2] [,3]
    [1,]   15    0    6
    [2,]   18   36   24
    Result of division 
         [,1]      [,2]      [,3]
    [1,]  0.6      -Inf 0.6666667
    [2,]  4.5 0.4444444 1.5000000