Question: How to test for matrix type/size?

I am trying to check if the inputs are a pair of row or column matrices. How should I do that? I have tried type but no success.


 

restart

 

TestDim:=proc(p1::{Matrix(1,3),Matrix(3,1)},p2::{Matrix(1,3),Matrix(3,1)},prnt::boolean:=Prntmsg)
description "Midpoints, Bilines";
uses RationalTrigonometry;
local x1, y1, z1, x2, y2, z2,m1,m2,xpsn , ypsn,zpsn ;

if [Dimension(p1)]=[1,3] and [Dimension(p2)]=[1,3] then  
      m1:= Vector[row](3);
      m2:= Vector[row](3);
      print([1,3]);
  elif [Dimension(p1)]=[3,1]and [Dimension(p2)]=[3,1] then
      m1:= Vector[column](3);
      m2:= Vector[column](3);
       print([3,1]);
 else
      ERROR(p1,p2, `must both be row or column matrices`);
end if;
end proc

proc (p1::{Matrix(1, 3), Matrix(3, 1)}, p2::{Matrix(1, 3), Matrix(3, 1)}, prnt::boolean := Prntmsg) local x1, y1, z1, x2, y2, z2, m1, m2, xpsn, ypsn, zpsn; description "Midpoints, Bilines"; if [Dimension(p1)] = [1, 3] and [Dimension(p2)] = [1, 3] then m1 := Vector[row](3); m2 := Vector[row](3); print([1, 3]) elif [Dimension(p1)] = [3, 1] and [Dimension(p2)] = [3, 1] then m1 := Vector[column](3); m2 := Vector[column](3); print([3, 1]) end if end proc

(1)

f:=<<a|b|c>>;
g:=<<d|e|h>>

f := Matrix(1, 3, {(1, 1) = a, (1, 2) = b, (1, 3) = c})

 

g := Matrix(1, 3, {(1, 1) = d, (1, 2) = e, (1, 3) = h})

(2)

TestDim(f,g)

 


 

Download 2024-08-18_Test_Matrix_Dimension.mw

Please Wait...