Function construction and also symmetric matrices
- To: mathgroup at smc.vnet.net
- Subject: [mg108469] Function construction and also symmetric matrices
- From: "Diamond, Mark" <dot at dot.dot>
- Date: Fri, 19 Mar 2010 02:47:34 -0500 (EST)
I am trying to construct a number of symmetric matrices with unit diagonal
and random numbers in the off-diagonal entries. The matrices are of steadily
increasing size. I have been constructing the matrices from random vectors
with the correct number of off-diagonal entries, so that for a 3x3 matrix I
have:
symmetricMatrix[l_,3]:={{1,l[[1]],l[[2]]},{l[[1]],1,l[[3]]},{l[[2]],l[[3]],1}}
symmetricMatrix[#,3]&/@RandomReal[{0,1},{10000,3}]
or, for a 4x4 matrix
symmetricMatrix[l_,6]:={{1,l[[1]],l[[2]],l[[4]]},{l[[1]],1,l[[3]],l[[5]]},{l[[2]],l[[3]],1,l[[6]]},{l[[4]],l[[5]],l[[6]],1}}
symmetricMatrix[#,6]&/@RandomReal[{0,1},{10000,6}]
The method works but writing the function symmetricMatrix by hand
error-prone for large matrices. ...
My first question is whether I have overlooked a much better (i.e.,
computationally faster) way of producing the matrices. Something which
avoids all the calls to Part (e.g., l[[7]]) might be good.
My second question relates not only to symmetric matrices but to a problem
that I face frequently in other areas. Is there a way of constructing the
symmetricMatrix function automatically? This is different from the question
about a good way of constructing symmetric matrices. Here I am asking
whether, given an appropriate matrix size, n, I can get Mathematica to
create the static function in the form that I have written
symmetricMatrix[3] and symmetricMatrix[6] ... so that, for example, if I
enter
makeStaticSymmetricMatrixFunctionForSize[3]
and then enter
?makeSymmetricMatricFunction
Mathematic will show me that there now exists a function like
symmetricMatrix[l_,3]:={{1,l[[1]],l[[2]]},{l[[1]],1,l[[3]]},{l[[2]],l[[3]],1}}
??
I would appreciate any help or suggestions.
Cheers,
Mark Diamond