# How to code in Maple for testing a sequare Matrix

I am writing a procedure in Maple for doing some optimization. Really now I want to ask Maple whether the Matrix is 2x2 or 3x3 or 4x4 and so on. And in each case of these matrices I am going to do something. Also, to know if the matrix is not sequare, i am going to do something else. I know that the command Dimension(A) gives you the dimension of the matrix, but I am not sure if it is the needed command to be used, and if it is so, how to use it?

Can any one help me in this issue?

Thank you.

• The Maple documentation is going to be infinitely more valuable for questions like this. It even includes examples. See here. – AnonSubmitter85 Jul 11 '13 at 2:12

Questions about programming in Maple whose main focus is not on the mathematics of the algorithms are better suited for stackoverflow.com or mapleprimes.com

f := proc(M::Matrix)
local m,n;
(m,n) := LinearAlgebra:-Dimension(M);
if m <> n then
"the nonsquare case";
elif m = 2 then
"the 2-by-2 case";
elif m = 3 then
"the 3-by-3 case";
else
"some other case";
end if;
end proc:

f( Matrix(3,4) );

"the nonsquare case"

f( Matrix(2,2) );

"the 2-by-2 case"

f( Matrix(3,3) );

"the 3-by-3 case"

f( Matrix(4,4) );

"some other case"

• So, this is the ideal one! – Mhenni Benghorbal Jul 11 '13 at 10:56