       Re: Re: lower diagonal matrix

• To: mathgroup at smc.vnet.net
• Subject: [mg80496] Re: [mg80429] Re: lower diagonal matrix
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Thu, 23 Aug 2007 06:21:32 -0400 (EDT)
• References: <fae9s7\$eai\$1@smc.vnet.net> <20312683.1187786998634.JavaMail.root@m35>

```5 * 56 isn't a triangular number, so I have to assume your 5x56 matrix
ISN'T a 5x56 matrix, since it has only 253 elements:

5*56
Floor[1/2 (-1 + Sqrt[1 + 8 k])] /. k -> 280
Binomial[23, 2]

280

23

253

If your imported data is too long (probably not), use the math above to
determine the number of rows and columns in the target matrix, then
discard the blank or garbage cells at the end using Take[input,253]. (Or
ignore it, since the code below won't touch them.)

Here's a 5x5 example:

k = 5;
flat = Range[k (k + 1)/2]

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}

Set "flat" equal to your data, k = the expected matrix size, and then:

Clear[m]
m[r_, c_] /; c <= r := flat[[c + (r - 1) r/2]]
m[r_, c_] := m[c, r]
matrix = Array[m, {k, k}];
matrix // MatrixForm

1	2	4	7	11
2	3	5	8	12
4	5	6	9	13
7	8	9	10	14
11	12	13	14	15

Bobby

On Wed, 22 Aug 2007 03:45:30 -0500, Ray Koopman <koopman at sfu.ca> wrote:

> On Aug 21, 2:05 am, Sean Bonness <nbonn... at chem.ucsb.edu> wrote:
>> Hello...
>>
>> I am in need of some help in trying to convert data I got from
>> another program into mathematica so that I can eventually diagonalize
>> the matrix. What I have from the other program are values for a lower
>> diagonal matrix, which corresponds to a full symmetric matrix and
>> whereby the program tries to save on writing alot of data by just
>> writing the lower diagonal matrix. The values I have from another
>> program are in a five column by 56 row matrix. The first element
>> (1,1) in this matrix corresponds to the (1,1) element in a lower
>> diagonal matrix, the second element (1,2) corresponds to (2,1), the
>> third (1,3) corresponds to (2,2), the fourth (1,4) corresponds to
>> (3,1), the fifth (1,5) corresponds to (3,2), the sixth (2,1)
>> corresponds to (3,3) and so on. What I have done so far is read in
>> the data into mathematica, but when I do it reads it in as a one
>> dimensional list. What I would like to do is to break up the data
>> into a human readable form of a lower diagonal matrix and then
>> construct a full symmetric (23x23) matrix of this data so as to
>> eventually diagonalize and solve it. The lower diagonal elements are
>> the same as the upper diagonal elements, so I understand that I would
>> need to specify the elements to be a[i,j]=a[j,i] somewhere in
>> defining the symmetric matrix. Any help in trying to help me write/
>> construct the full symmetric matrix from the data I have would be
>> much appreciated.
>
> Here's a toy example for a 4 x 4 matrix:
>
> k[i_,j_] := #(#-1)/2&@Max[i,j] + Min[i,j]
>
> Table[k[i,j],{i,4},{j,4}]
>
> {{1, 2, 4, 7},
>  {2, 3, 5, 8},
>  {4, 5, 6, 9},
>  {7, 8, 9, 10}}
>
> t = Flatten@Table[Random[],{2},{5}]
>
> {0.963279, 0.290362, 0.347601, 0.300672, 0.184255,
>  0.249541, 0.666380, 0.371960, 0.026704, 0.187856}
>
> Table[t[[k[i,j]]],{i,4},{j,4}]
>
> {{0.963279, 0.290362, 0.300672, 0.666380},
>  {0.290362, 0.347601, 0.184255, 0.371960},
>  {0.300672, 0.184255, 0.249541, 0.026704},
>  {0.666380, 0.371960, 0.026704, 0.187856}}
>
>
>

--

DrMajorBob at bigfoot.com

```

• Prev by Date: Re: Plot
• Next by Date: Re: From PaddedForm to numbers?
• Previous by thread: Re: lower diagonal matrix
• Next by thread: Do You Know?