MathGroup Archive 2007

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

Search the Archive

Re: copying values of entries between matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78014] Re: [mg77952] copying values of entries between matrices
  • From: Curtis Osterhoudt <cfo at lanl.gov>
  • Date: Thu, 21 Jun 2007 05:48:04 -0400 (EDT)
  • Organization: LANL
  • References: <200706200937.FAA10111@smc.vnet.net> <200706201240.58706.cfo@lanl.gov>
  • Reply-to: cfo at lanl.gov

I screwed up on what I was calling matrices in my reply. In my reply, please 
replace "s" and/or "dOneCol" with your "entMat", and set "dOneCol" equal to 
the result! Sorry for the mix-up on my part.

           C.O.

On Wednesday 20 June 2007 12:40:58 Curtis Osterhoudt wrote:
> If you have v. 6 of Mathematica, the function "diagonal" should help you
> out; to get a list of the elements you want, try
>
> Diagonal[s, #]&/@Range[-(Length@s) + 1, 0]
>
> Of course, if you want these elements on the same level in your dOneCol,
>
> Flatten@Diagonal[s, #]&/@Range[-(Length@s) + 1, 0]
>
>
>
> If you have an earlier version, you could try something like the following
> (which I haven't optimized for different types of lists or anything, but
> should work for matrix arguments):
>
> takeLowerLeft[mat_]:=Take[mat, {2, Length@mat}, {1, Length@mat - 1}]
>
> snagDiags[mat_] := mat[[#, #]] & /@ Range[Length[mat]]
>
> snagDiags /@ NestList[ takeLowerLeft,  dOneCol, Length[dOneCol] -1 ]
>
> Flatten@%
>
>
>
>     Hope that helps!
>
>                      C.O.
>
> On Wednesday 20 June 2007 03:37:37 text.tex wrote:
> > Hi,
> > here is my problem:
> > I have a 18x18 matrix called entMatr.
> > I want to copy the values of the elements of the lower left half of
> > entMatr into a 171x1 matrix called dOneCol.
> > I had tried a 3-nested loop for copying the values from entMatr to
> > dOneCol; the current version where I tried to replace the loop over
> > the rows of dOneCol with a counter q produces a result, however the
> > result is not what I want...
> >
> > I'd greatly appreciate any pointers how to get this working!
> > Thanks,
> > Claus
> >
> > This is what I tried:
> >
> > <pre>
> >  (* initialize entMatr *)
> > entMatr = Table[Subscript[m, i, j], {i, 18}, {j, 18}];
> >
> >  (* fill the lower left half of entMatr with some values *)
> > For[i = 1, i < 18 + 1, i++,
> >  For[j = i, j < 18 + 1, j++,
> >   entMatr[[j, i]] = i
> >   ]
> >  ]
> >
> >  (* initialize dOneCol *)
> > dOneCol = Table[Subscript[n, x], {x, 171}];
> >
> >  (* attempt to copy the values from entMatr to dOneCol *)
> > q = 0;
> > For[k = 1, k < 18 + 1, k++,
> >  For[p = k, p < 18 + 1, p++,
> >   dOneCol[[q]] = entMatr[[p,k]]
> >     q++
> >   ]
> >  ]
> > dOneCol
> > </pre>



-- 
==========================================================
Curtis Osterhoudt
cfo at remove_this.lanl.and_this.gov
PGP Key ID: 0x4DCA2A10
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================


  • Prev by Date: Re: Inequalities
  • Next by Date: Re: ComplexExpand in Mathematica 5.2 and 6
  • Previous by thread: Re: copying values of entries between matrices
  • Next by thread: Re: copying values of entries between matrices