Re: Applying transformation rule to matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg9850] Re: [mg9720] Applying transformation rule to matrix
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Fri, 28 Nov 1997 05:36:06 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Gary L. Hennigan wrote: > > I have a symbolic matrix created as > > pos=Array[p,{4,3}] > > and a corresponding matrix that stores actual values, e.g., > > posval={{1,2,3},{4,5,6},{7,8,9},{1,2,3}} > > I perform some operations on "pos" to get several other variables and > now I'd like to apply a transformation rule to see what the numerical > value of those resulting variables is with the values in "posval". > Assuming "var1" is some function of the elements in the matrix "pos", > is there an easier way to do this than: > > var1 /. {pos[[1,1]]->posval[[1,1]],...,pos[[4,3]]->posval[[4,3]]} > > The string of transformation rules in {}'s gets quite long for a 4x3 > matrix and it's a bit annoying having to cut and paste the thing > around. Gary: The list of rules is easily constructed: pos=Array[p,{4,3}]; posval={{1,2,3},{4,5,6},{7,8,9},{1,2,3}}; Flatten[MapThread[Rule,{pos,posval},2]] {p[1, 1] -> 1, p[1, 2] -> 2, p[1, 3] -> 3, p[2, 1] -> 4, p[2, 2] -> 5, p[2, 3] -> 6, p[3, 1] -> 7, p[3, 2] -> 8, p[3, 3] -> 9, p[4, 1] -> 1, p[4, 2] -> 2, p[4, 3] -> 3} Allan Hayes Mathematica Training and Consulting Leicester, UK hay at haystack.demon.co.uk http://www.haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44 (0)116 271 4198