# Using Table to make a set of replacement rules for functions

I have a 3x3 matrix of functions. It looks like

k1[xx_]:={
{k1[1,1][xx],k1[1,2][xx],k1[1,3][xx]},
{k1[1,2][xx],k1[2,2][xx],k1[2,3][xx]},
{k1[1,3][xx],k1[2,3][xx],k1[3,3][xx]}
}


(It's symmetric on the first two arguments.) I want to replace all of the k1[i,j] functions with different functions. What I want to do is, basically

Flatten[Table[
k1[a, b] -> (1/c^4 k1c4[a, b][#] &), {a, 1, 3}, {b, 1, 3}]]


or with slightly different syntax

  Flatten[Table[
k1[a, b] -> Function[xx,1/c^4 k1c4[a, b][xx]], {a, 1, 3}, {b, 1, 3}]]


Neither of these work. Instead of a matrix

{
{k1c4[1,1][xx],k1c4[1,2][xx],k1c4[1,3][xx]},
{k1c4[1,2][xx],k1c4[2,2][xx],k1c4[2,3][xx]},
{k1c4[1,3][xx],k1c4[2,3][xx],k1c4[3,3][xx]}
}


I get a matrix

{
{k1c4[a,b][xx],k1c4[a,b][xx],k1c4[a,b][xx]},
{k1c4[a,b][xx],k1c4[a,b][xx],k1c4[a,b][xx]},
{k1c4[a,b][xx],k1c4[a,b][xx],k1c4[a,b][xx]}
}


which is meaningless because a and b aren't defined anywhere.

How can I make the replacement list I want using something like Table?

## 1 Answer

SetAttributes[k1, Orderless];
kk1[xx_] := Array[k1[##][xx] &, {3, 3}]
kk1[xx]


{{k1[1, 1][xx], k1[1, 2][xx], k1[1, 3][xx]},
{k1[1, 2][xx], k1[2, 2][xx], k1[2, 3][xx]},
{k1[1, 3][xx], k1[2, 3][xx], k1[3, 3][xx]}}

You can use With in the first argument of Table to inject values of the iterator variables a and b into the rule elements:

rules = Flatten[ Table[With[{a = a, b = b}, k1[a, b] -> (1/c^4 k1c4[a, b][#] &)],
{a, 1, 3}, {b, 1, 3}]];

kk1[[x]] /. rules


A simpler alternative is to use Patterns to define the replacement rule:

rule = k1[a__][xx] :>  k1c4[a][xx] / c^4;
kk1[xx] /. rule


same result