MathGroup Archive 2004

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

Search the Archive

Re: [Outer [Times, , ] ] Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45823] Re: [Outer [Times, , ] ] Question
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Mon, 26 Jan 2004 01:53:32 -0500 (EST)
  • References: <bv00aa$jda$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

MatrixForm objects don't add, because they're not matrices.  But your
code works perfectly for me, because (see a recent thread on
MatrixForm), I have installed the following code in my Init.m file
(thanks to Andrzej Kozlowski):

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]]
Protect[MatrixForm];

Bobby

MichaelSMcCain at cs.com wrote in message news:<bv00aa$jda$1 at smc.vnet.net>...
> Hi:
> 
> I want to take a Column Vector and multiply it by a Row Vector to create an 
> "Outer" Matrix. 
> 
> In other words, I want to take a 5x1 Column Vector and multiply it by a 1x4 
> Row Vector and output a 5x4 Matrix.
> 
> I then want to add several of these Matrices together and obtain a "final" 
> Matrix.
> 
> I tried the following:
> 
> x1 = {1, -1, -1, 1, 1};
> y1 = {1, 1, -1, -1};
> 
> x2 = {-1, 1, -1, 1, -1};
> y2 = {1, -1, 1, -1};
> 
> x3 = {1, 1, -1, -1, 1};
> y3 = {-1, -1, 1, 1};
> 
> m1 = MatrixForm[Outer [Times, x1, y1] ]
> m2 = MatrixForm[Outer [Times, x2, y2] ]
> m3 = MatrixForm[Outer [Times, x3, y3] ]
> 
> mm = m1 + m2 + m3
> 
> MatrixForm[mm]
> 
> The output that I get is incorrect and does not combine into a single Matrix.
> 
> 
> What am I doing wrong?
> 
> Thanks,
> 
> 
> Mike McCain
> MichaelSMcCain at cs.com


  • Prev by Date: RE: Stretching X-Axis in Plot[]
  • Next by Date: Re: RE: Re: copying
  • Previous by thread: RE: [Outer [Times, , ] ] Question
  • Next by thread: Re: [Outer [Times, , ] ] Question