Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45397] Re: Transpose matrix does not work when MatrixForm is used, why?
  • From: "Ersek, Ted CIV NASPATUXENTRIVERMD 4.5.1.2" <ted.ersek at navy.mil>
  • Date: Tue, 6 Jan 2004 04:16:56 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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?