MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Applying transformation rule to matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9810] Re: [mg9720] Applying transformation rule to matrix
  • From: Hugh Walker <hwalker at hypercon.com>
  • Date: Fri, 28 Nov 1997 05:35:23 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

"Gary L. Hennigan" <glhenni at cs.sandia.gov> writes:

>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. I don't want to assign pos=posval because I may define other
>symbolic variables that are functions of "pos" later.
>
>Of importance may be that I'm using v2.2 on a Sparc under Solaris.
>
>I'm still learning Mathematica so be gentle if this is a dumb question!
>

Hello Gary:

Unless your function varl is something strange indeed, I think the
solution of your problem is fairly straightforward. Let m = any
symbolic array, and nN = a numerical list with the same dimensions as
m. Let f be any function defined in terms of the components of m. Then
your desired results lie in execution of the rule:  matrule  =
Thread[Flatten[m]->Flatten[mN]]. The effects of this are to first
obtain simple 1-dimenional lists from both m and mN and then thread a
replacement through the two lists.

Example:

m = Array[a,{2,2}];
mN = Table[Random[],{i,2},{j,2}];
m.m/.Thread[Flatten[m]->Flatten[mN]]

This may not be exactly what you wanted, but it will work. Several
experienced users can, and probably will, provide more elegant
suggestions. By the way, I didn't find your question trivial by any
means.

Cheers!

Hugh Walker
Gnarly Oaks




  • Prev by Date: Re: 2nd Try!
  • Next by Date: Assigment statements
  • Previous by thread: Applying transformation rule to matrix
  • Next by thread: Re: Applying transformation rule to matrix