Re: assignment of matrix elements
- To: mathgroup at smc.vnet.net
- Subject: [mg17277] Re: [mg17206] assignment of matrix elements
- From: BobHanlon at aol.com
- Date: Fri, 30 Apr 1999 02:34:53 -0400
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 4/26/99 5:19:29 AM, rfinley at medicine.umsmed.edu writes:
>If you have a matrix say mat = Array[m, {4,4}]
>
>and a list of indices say v = {{1,2},{1,3},{2,3},{3,1}}
>with another list of the same length giving the values of the matrix
>elements at
>those indices: w = {1,5,-2,1}
>
>How do you assign values to the matrix elements with those values...ie
>
>so
>that m[1,2]=1, m[1,3]=5 etc...
>
>Obviously you can do it individually by simple assignment:
>m{1,2]=1
>
>That won't work for me because there are thousands of elements...the
>techniques I have tried so far
>have not worked...any help is greatly appreciated.
>
Richard,
Clear[m, mat, v, w];
mat = Array[m, {4, 4}];
v = {{1,2},{1,3},{2,3},{3,1}};
w = {1,5,-2,1};
Evaluate[m[Sequence @@ #]& /@ v] = w;
mat
{{m[1, 1], 1, 5, m[1, 4]}, {m[2, 1], m[2, 2], -2, m[2, 4]},
{1, m[3, 2], m[3, 3], m[3, 4]},
{m[4, 1], m[4, 2], m[4, 3], m[4, 4]}}
Bob Hanlon