Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*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 2000

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

Search the Archive

Re: Factor MatrixForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21389] Re: [mg21383] Factor MatrixForm
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 1 Jan 2000 20:54:47 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Bob,

I have often wished to do the same thing because text books often have symbolic
arrays in a factored form. However, Mathematica always multiplies any factors into
a list. The only solution I know is to put the list into a HoldForm and then
remember to release it if you need to. Here are two separate routines, one for
matrices and the other for vectors which I believe will work:

factormatrix[matrix_?MatrixQ] :=
  Module[{wmatrix, list, fac},
    wmatrix = Map[Factor, matrix, {2}];
    wmatrix = list @@ wmatrix;
    fac = wmatrix /. list[{_ h_.} ..] -> h;
    wmatrix = fac(#/fac & /@ wmatrix) /. list[x__] -> HoldForm[List[x]];
    If[fac === 1, ReleaseHold[wmatrix], wmatrix]]

factormatrix[{{a h}, {b h}, {c h}}]
h {{a}, {b}, {c}}

factormatrix[{{a h1 h2}, {b h1 h2}, {c h1 h2}}]
h1 h2 {{a}, {b}, {c}}

factormatrix[{{a h}, {b h}, {c }}]
{{a h}, {b h}, {c}}

factormatrix[{{Cos[a]Sin[b]H}, {-Sin[a]k w H - 5Sin[b]k H}, {-2Cos[2a]H}}]
% /. HoldForm[x_] :> MatrixForm[x]
H {{Cos[a] Sin[b]}, {-k (w Sin[a] + 5 Sin[b])}, {-2 Cos[2 a]}}
- MatrixForm not shown -

factorvector[vector_?VectorQ] :=
  Module[{wvector, list, fac},
    wvector = Map[Factor, vector, {1}];
    wvector = list @@ wvector;
    fac = wvector /. list[_ h_. ..] -> h;
    wvector = fac(#/fac & /@ wvector) /. list[x__] -> HoldForm[List[x]];
    If[fac === 1, ReleaseHold[wvector], wvector]]

factorvector[{a h, b h, c h}]
h {a, b, c}

factorvector[{a h1 h2, b h1 h2, c h1 h2 }]
h1 h2 {a, b, c}

factorvector[{a h, b h, c }]
{a h, b h, c}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

>I'm not sure what operation I want to perform on my list.  Factor
>almost does what I want.  What I have is, after many operations,
>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
>----------------------------------------------------------------
>







  • Prev by Date: Re: FourierTransform[Sign[t], t, w, FourierParameters -> {1, -1}]
  • Next by Date: Re: A better way to decimate a file??
  • Previous by thread: Re: Factor MatrixForm
  • Next by thread: Re: Factor MatrixForm