MathGroup Archive 2001

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

Search the Archive

Re: simple questions about matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26530] Re: simple questions about matrices
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 3 Jan 2001 04:08:47 -0500 (EST)
  • References: <9217dp$cnv@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Cristian:
>(a) I have a (m,n) matrix a with integer entries. How can I construct
>a separate list with the totals of adding the entries of either the
> rows or columns?

M = {{1, 2}, {3, 4}, {5, 6}}

{{1, 2}, {3, 4}, {5, 6}}

Plus @@ M

{9, 12}

Plus @@ Transpose[M]

{3, 7, 11}

>(b) How can I construct a (m+1,n) matrix where the new row's entries
> are the sums of all numbers on each column?

Append[M, Plus @@ M]

{{1, 2}, {3, 4}, {5, 6}, {9, 12}}

(c) In general, how can I attach additional columns (o rows) to an
existing matrix?

Transpose[Append[Transpose[M], {a, b, c}]]

{{1, 2, a}, {3, 4, b}, {5, 6, c}}

Append[M, {a, b}]

{{1, 2}, {3, 4}, {5, 6}, {a, b}}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Cristian Opazo-Castillo" <cropazo at vassar.edu> wrote in message
news:9217dp$cnv at smc.vnet.net...
> Hello all:
>
> I hope that someone is still working and could help me with this...
>
> (a) I have a (m,n) matrix a with integer entries. How can I construct
> a separate list with the totals of adding the entries of either the
> rows or columns?
>
> (b) How can I construct a (m+1,n) matrix where the new row's entries
> are the sums of all numbers on each column?
>
> (c) In general, how can I attach additional columns (o rows) to an
> existing matrix?
>
> Thanks a lot and Happy Holidays,
>
> Cristian
>
>




  • Prev by Date: Re: Automatic Numbering
  • Next by Date: Re: Call for all people presenting the Louis or Carl, Big trouble syndrom
  • Previous by thread: Re: please tell me if individual contours can be labled in ContourPlot
  • Next by thread: Re: Call for all people presenting the Louis or Carl, Big trouble syndrom