       Re: assignment of matrix elements

• To: mathgroup at smc.vnet.net
• Subject: [mg17245] Re: assignment of matrix elements
• From: jf alcover <jfalcover at cepme.fr>
• Date: Fri, 30 Apr 1999 02:34:37 -0400
• Organization: cepme
• References: <7g0r8r\$dsc@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```this is what i suggest :

In:=mat = Array[m, {4,4}];
v = {{1,2},{1,3},{2,3},{3,1}};
w = {1,5,-2,1};

In:=assign[{x_,y_},z_]:=(mat[[x,y]]=z);

In:=mat
Out:={{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]}}

regards,

Richard Finley wrote:

> This seems like it should be straightforward but I am too tired to think
>
> 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.
>
> Thanks
>
> Richard Finley

```

• Prev by Date: Re: Re: my previous question on matrix element assignment
• Next by Date: Re: Mathematica in Chemistry
• Previous by thread: Re: assignment of matrix elements
• Next by thread: Re: assignment of matrix elements