Question: multipliying nonconformable matrices should give an error message.

I made an error by trying to multiply two nonconformable matrices. I think, I should receive an error message. But in this example this did not occur.

Strange.mw

restart; with(LinearAlgebra); alias(`⨂` = LinearAlgebra:-KroneckerProduct); interface(rtablesize = 16); kernelopts(version); interface(version)

`⨂`

[10, 10]

`Maple 2021.2, X86 64 LINUX, Nov 23 2021, Build ID 1576349`

`Standard Worksheet Interface, Maple 2021.2, Linux, November 23 2021 Build ID 1576349`

Matrices nonconformable, Maple should give error message:

`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)); Dimension(%); M := Matrix(4, 4, shape = symmetric, symbol = m); Dimension(%)

Matrix([[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]])

4, 16

M := Matrix(4, 4, {(1, 1) = m[1, 1], (1, 2) = m[1, 2], (1, 3) = m[1, 3], (1, 4) = m[1, 4], (2, 2) = m[2, 2], (2, 3) = m[2, 3], (2, 4) = m[2, 4], (3, 3) = m[3, 3], (3, 4) = m[3, 4], (4, 4) = m[4, 4]}, storage = triangular[upper], shape = [symmetric])

4, 4

MatrixMatrixMultiply(`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)), DiagonalMatrix(Diagonal(M)))

Matrix([[m[1, 1], 0, 0, 0], [0, m[2, 2], 0, 0], [0, 0, m[3, 3], 0], [0, 0, 0, m[4, 4]]])

`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)).DiagonalMatrix(Diagonal(M))

Matrix([[m[1, 1], 0, 0, 0], [0, m[2, 2], 0, 0], [0, 0, m[3, 3], 0], [0, 0, 0, m[4, 4]]])

KroneckerProduct(Matrix(1, 4, 1), IdentityMatrix(4)).DiagonalMatrix(Diagonal(M))

Matrix([[m[1, 1], 0, 0, 0], [0, m[2, 2], 0, 0], [0, 0, m[3, 3], 0], [0, 0, 0, m[4, 4]]])

(Matrix(4, 16, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 1, (1, 6) = 0, (1, 7) = 0, (1, 8) = 0, (1, 9) = 1, (1, 10) = 0, (1, 11) = 0, (1, 12) = 0, (1, 13) = 1, (1, 14) = 0, (1, 15) = 0, (1, 16) = 0, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (2, 6) = 1, (2, 7) = 0, (2, 8) = 0, (2, 9) = 0, (2, 10) = 1, (2, 11) = 0, (2, 12) = 0, (2, 13) = 0, (2, 14) = 1, (2, 15) = 0, (2, 16) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1, (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (3, 7) = 1, (3, 8) = 0, (3, 9) = 0, (3, 10) = 0, (3, 11) = 1, (3, 12) = 0, (3, 13) = 0, (3, 14) = 0, (3, 15) = 1, (3, 16) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1, (4, 5) = 0, (4, 6) = 0, (4, 7) = 0, (4, 8) = 1, (4, 9) = 0, (4, 10) = 0, (4, 11) = 0, (4, 12) = 1, (4, 13) = 0, (4, 14) = 0, (4, 15) = 0, (4, 16) = 1})).DiagonalMatrix(Diagonal(M))

Matrix([[m[1, 1], 0, 0, 0], [0, m[2, 2], 0, 0], [0, 0, m[3, 3], 0], [0, 0, 0, m[4, 4]]])

`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)).Matrix(4, 4, shape = diagonal, symbol = m)

Matrix([[m[1, 1], 0, 0, 0], [0, m[2, 2], 0, 0], [0, 0, m[3, 3], 0], [0, 0, 0, m[4, 4]]])

whattype(`⨂`(Matrix(1, 4, 1), IdentityMatrix(4))); Dimension(`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)))

Matrix

4, 16

whattype(DiagonalMatrix(Diagonal(M))); Dimension(M)

Matrix

4, 4

hereafter results are correct: Matrices

nonconformable, therefore error messages appear.

`⨂`(Matrix(1, 4, 1), IdentityMatrix(4)).M

Error, (in LinearAlgebra:-Multiply) first matrix column dimension (16) <> second matrix row dimension (4)

`&bigotimes;`(Matrix(1, 4, 1), IdentityMatrix(4)).Matrix(4, 4, shape = symmetric, symbol = m)

Error, (in LinearAlgebra:-Multiply) first matrix column dimension (16) <> second matrix row dimension (4)

Download Strange.mw

Please Wait...