MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Transpose matrix does not work when MatrixForm is used, why?


Recall the recent thread on how do ensure we can do math on matrices 
wrapped in MatrixForm. 
Apparently other solutions didn't quite do the trick.  I think the code 
below is better.
(*------------------------------------------*)

Unprotect[MatrixForm];

HeadTest[func_]:= Intersection[{func},
  =
{If,List,Set,SetDelayed,UpSet,UpSetDelayed,TagSet,TagSetDelayed,Format,
     =
MakeBoxes,MakeExpression,ToBoxes,Shallow,Short,Hold,HoldForm,HoldComplete=
,
     =
HoldPattern,Verbatim,Blank,BlankSequence,BlankNullSequence,Alternatives, 

     Pattern,Optional,Repeated,RepeatedNull,Condition,PatternTest,Rule,
     RuleDelayed,FullForm,InputForm
   }]==={}


MatrixForm/:(f_?HeadTest)[a1___, a2_MatrixForm, a3___]:=
  Module[{result},
    result = Replace[ {a1,a2,a3}, MatrixForm->Identity, 2, Heads->True 
];
      result = f@@result;
     If[ MatrixQ@result, MatrixForm[result], result ]
    ]


(*---------------------------------------------------------*)
Now we can do the following and get the output in MatrixForm.


  m1=MatrixForm[{{2,3,4},{1,5,2},{6,3,1}}]

  Inverse[m1]

  MatrixPower[m1,4]

  m2={{2,0,4},{0,5,2},{0,3,1}};
  m1.m1.m1.m2

  Det[m1]

  Part[m1,1,3]


----------------
Regards,
   Ted Ersek

Download Mathematica Tips From
http://www.verbeia.com/mathematica/tips/Tricks.html



  • Prev by Date: Re: Mathematica exports curves in pieces to Illustrator
  • Next by Date: what's wrong about my package?
  • Previous by thread: Re: Transpose matrix does not work when MatrixForm is used, why?
  • Next by thread: Re: Transpose matrix does not work when MatrixForm is used, why?