Re: Factor MatrixForm
- To: mathgroup at smc.vnet.net
- Subject: [mg21405] Re: Factor MatrixForm
- From: Gianluca Gorni <gorni at dimi.uniud.it>
- Date: Tue, 4 Jan 2000 02:12:36 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I already thought about how to format a symbolic list or matrix with
a common factor collected out, and I solved it by using PolynomialGCD[]
and PrecedenceForm[].
My full code is here (the variable names are an Italian/English hybrid):
collectFactorFromLists[exprList_List] :=
Module[{fatt, sempl},
fatt = PolynomialGCD @@ Flatten[{exprList}];
If[StringMatchQ[ToString[InputForm[fatt]], "-*"],
fatt = -fatt];
sempl = If[fatt =!= 0, Simplify[Expand[exprList/fatt]]];
If[fatt === 0 || fatt === 1,
If[ByteCount[exprList] < 500,
MatrixForm[exprList], exprList],
PrecedenceForm[Simplify[fatt], 1]*
PrecedenceForm[If[ByteCount[sempl] < 500 && MatrixQ[sempl],
MatrixForm[sempl], sempl]]]];
collectFactorFromLists[expr_ /; Head[expr] =!= List] := expr;
When you want to use the output for further calculations,
you have do deformat it first by applying the rules
PrecedenceForm[a_,___]:>a and MatrixForm -> Identity.
Good luck.
Gianluca Gorni
--
+---------------------------------+
| Gianluca Gorni |
| Universita` di Udine |
| Dipartimento di Matematica |
| e Informatica |
| via delle Scienze 208 |
| I-33100 Udine UD |
| Italy |
+---------------------------------+
| Ph.: (39) 0432-558422 |
| Fax: (39) 0432-558499 |
| mailto:gorni at dimi.uniud.it |
| http://www.dimi.uniud.it/~gorni |
+---------------------------------+
> a list in MatrixForm, something like this:
>
> MatrixForm[t]
>
> [ Cos[a]Sin[b]H - Sin[a]Sin[b]H ]
> [ -Sin[a]k*w*H - 5*Sin[b]*k*H ]
> [ -2Cos[2a]H ]
>
> What manipulation do I perform to get it to look like
>
> [ Cos[a]Sin[b] - Sin[a]Sin[b] ]
> H*[ -Sin[a]k*w - 5*Sin[b]*k ]
> [ -2Cos[2a] ]
>
>
>
> --
> ----------------------------------------------------------------
> Bob Love
> rlove at neosoft.com
> ----------------------------------------------------------------