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: [mg77977] Re: copying values of entries between matrices
  • From: Norbert Marxer <marxer at mec.li>
  • Date: Thu, 21 Jun 2007 05:28:56 -0400 (EDT)
  • References: <f5atd0$an9$1@smc.vnet.net>

On 20 Jun., 11:52, "text.tex" <Clausena... at gmail.com> 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>

Hello

You have to modify two things.

1. Missing semicolon

There is no semicolon between the command  "dOneCol[[q]] =
entMatr[[p,k]]" and the command "q++". Therefore each entry of dOneCol
is multiplied by the actual value of q.

2. q starts at 0

This means that with your first assignment dOneCol[[0]] =
entMatr[[1,1]]" you modify the head of dOneCol. You can either set q=1
at the beginning or you can move q++ in front of the command
"dOneCol[[q]] = entMatr[[p, k]]". Both changes alone should work.

Finally. The following code should do what you want:

q = 1;
For[k = 1, k < 18 + 1, k++, For[p = k, p < 18 + 1, p++,
     dOneCol[[q]] = entMatr[[p, k]]; q++]]
dOneCol

Best Regards
Norbert Marxer



  • Prev by Date: Re: Reproducible crash in version 6
  • Next by Date: Re: Same Limit: OK in 5.2, fails in 6.0; Packages gone
  • Previous by thread: Re: copying values of entries between matrices
  • Next by thread: Re: copying values of entries between matrices