# Element assignment in matrix function

I have to define a function of two variables that yields a high dimensional matrix, with each entry containing a scalar function, that uses its coordinates in the matrix as input. like this:

f[x_,a_] := {{g[1,1][x]*a, g[1,2][x]*a}, {g[2,1][x]*a, g[2,2][x]*a}}


Is there any way I can assign the elements in a smart way without mapping the whole matrix by hand?

EDIT: I've been asked for an example of g. This is taken out of the original code:

g[n_, m_] := Table[Chop[
I*Conjugate[h[[n]][[i]]].(hx[[m]][[i]] - h[[m]][[i]])/
step, 3*10^-3],
{i, 1, Length[qvals]}];

• Use Array or Table. – Szabolcs Jul 22 '15 at 15:03
• Do you have an example of what g is here? – Arnoud Buzing Jul 22 '15 at 15:05
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey Jul 22 '15 at 15:07
• That's not a good example. It depends on many undefined free variables. – m_goldberg Jul 22 '15 at 16:27
• f[x_, a_] = a Array[g[##][x] &, {2, 2}] – Dr. belisarius Jul 22 '15 at 16:43

gs = Flatten @ Table[With[{m = m, n = n}, Sin[m #/n^2] &], {m, 2}, {n, 2}];

{Sin[#1/1^2] & , Sin[#1/2^2] & , Sin[(2*#1)/1^2] & , Sin[(2*#1)/2^2] &}

f[x_, a_] = a Through[gs[x]];

{b*Sin[u], b*Sin[u/4], b*Sin[2*u], b*Sin[u/2]}