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: [mg45452] 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: Wed, 7 Jan 2004 17:31:18 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

	A few days ago I replied to a question on how to ensure we can do math 
on matrices wrapped in MatrixForm. 

	My earlier solution when into infinite recursion  when one would try
	MatrixForm[m]  when (m) was already wrapped in MatrixForm. 
	My solution for that is to add an UpValue for the case
	      MatrixForm[MatrixForm[m_]]
	As far as I know the version below is free of problems.
> (*------------------------------------------*)
>
> 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[MatrixForm[m_]] ^:= MatrixForm[m];

> 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]
>
	MatrixForm[m1]

> ----------------
> Regards,
>    Ted Ersek
>
> Download Mathematica Tips From
> http://www.verbeia.com/mathematica/tips/Tricks.html
>



  • Prev by Date: Re: Windows ME fonts
  • Next by Date: RE: multiple list plot and frameticks
  • 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?