Evaluate two variable functions at given points?

Hi All,

Assume I have list of two variable function and want to evaluate at some point. First func. in first list 4x take first point {1/12, 1/6} and second func. 4y takes second point {1/6, 1/12}. and second func list at second point list and so on. How can I do this? I tried Map, Thread, Through, Apply but no luck. Any suggestion? Thanks..

f={{4 x, 4 y, 1 - 4 x + 4 y, 2 - 4 x, 2 - 4 y,1 + 4 x - 4 y}, {-1 + 4 x, 4 y, 2 - 4 x + 4 y, 3 - 4 x, 2 - 4 y, 
  4 x - 4 y}, {-2 + 4 x, 4 y, 3 - 4 x + 4 y, 4 - 4 x,2 - 4 y, -1 + 4 x - 4 y}, {4 x, -1 + 4 y, -4 x + 4 y, 2 - 4 x, 
  3 - 4 y, 2 + 4 x - 4 y}, {-1 + 4 x, -1 + 4 y, 1 - 4 x + 4 y,  3 - 4 x, 3 - 4 y, 1 + 4 x - 4 y}, {-2 + 4 x, -1 + 4 y, 
  2 - 4 x + 4 y, 4 - 4 x, 3 - 4 y,  4 x - 4 y}, {4 x, -2 + 4 y, -1 - 4 x + 4 y, 2 - 4 x, 4 - 4 y, 
  3 + 4 x - 4 y}, {-1 + 4 x, -2 + 4 y, -4 x + 4 y, 3 - 4 x, 4 - 4 y,   2 + 4 x - 4 y}, {-2 + 4 x, -2 + 4 y, 1 - 4 x + 4 y, 4 - 4 x, 
  4 - 4 y, 1 + 4 x - 4 y}}

pts={{{1/12, 1/6}, {1/6, 1/12}, {1/3, 1/6}, {5/12, 1/3}, {1/3, 5/12}, {1/
   6, 1/3}}, {{1/3, 1/6}, {5/12, 1/12}, {7/12, 1/6}, {2/3, 1/3}, {7/12, 5/12}, {5/12, 1/3}}, {{7/12, 1/6}, {2/3, 1/12}, {5/6, 1/
   6}, {11/12, 1/3}, {5/6, 5/12}, {2/3, 1/3}}, {{1/12, 5/12}, {1/6, 1/ 3}, {1/3, 5/12}, {5/12, 7/12}, {1/3, 2/3}, {1/6, 7/12}}, {{1/3, 5/
   12}, {5/12, 1/3}, {7/12, 5/12}, {2/3, 7/12}, {7/12, 2/3}, {5/12, 7/ 12}}, {{7/12, 5/12}, {2/3, 1/3}, {5/6, 5/12}, {11/12, 7/12}, {5/6, 
   2/3}, {2/3, 7/12}}, {{1/12, 2/3}, {1/6, 7/12}, {1/3, 2/3}, {5/12, 5/6}, {1/3, 11/12}, {1/6, 5/6}}, {{1/3, 2/3}, {5/12, 7/12}, {7/12, 
   2/3}, {2/3, 5/6}, {7/12, 11/12}, {5/12, 5/6}}, {{7/12, 2/3}, {2/3,  7/12}, {5/6, 2/3}, {11/12, 5/6}, {5/6, 11/12}, {2/3, 5/6}}}

I’m nut sure you are clear enough

Dimensions[f]

returns {9,6}
and

Dimensions[pts]

returns {9,6,2}

As I see it, for each expression in f (you have 9*6=54 of those) you need to replace x and y from the 54 pairs (in the same position) from its
The simple solution for that is to use MapThread at level 2 as follows. Note that that the level is required to use each instance of you functions with the correct pair of x and y values. Than use Thread to get a list of replacement rules so they will be used by the MapThread function (I forgot to add the Thread in my earlier reply.

MapThread[(#1 /.Thread[ {x, y} -> #2]) &, {f, pts}, 2]

you can also do it as

MapThread[#1 /. #2 & , {f, pts /. {a_, b_} :> {x -> a, y -> b}}, 2]

Evaluating one of the above for the given f and pts lists results with

{{1/3, 1/3, 1/3, 1/3, 1/3, 1/3}, {1/3, 1/3, 1/3, 1/3, 1/3, 1/3}, {1/3,
   1/3, 1/3, 1/3, 1/3, 1/3}, {1/3, 1/3, 1/3, 1/3, 1/3, 1/3}, {1/3, 1/
  3, 1/3, 1/3, 1/3, 1/3}, {1/3, 1/3, 1/3, 1/3, 1/3, 1/3}, {1/3, 1/3, 
  1/3, 1/3, 1/3, 1/3}, {1/3, 1/3, 1/3, 1/3, 1/3, 1/3}, {1/3, 1/3, 1/3,
   1/3, 1/3, 1/3}}

best
yehuda

Thanks for your reply. Sorry my unclear explanation. This is what I want

f[1,1][x_,y_]:=4x,  then f[1,1][pts[1,1]]=f[1,1][1/12, 1/6]=4*1/12=1/3
 f[1,2][x_,y_]:=4y, then f[1,2][pts[1,2]]=f[1,2][1/6, 1/12]=4*1/12=1/3
 f[1,3][x_,y_]:= 1 - 4 x + 4 y,  then f[1,3][pts[1,3]]=f[1,3][1/3, 1/6]=1-4*1/3+4*1/6=1/3

The way you have defined f, it is a little awkward to make it behave like a function. This is a solution, that uses two new symbols myF and myPts, which behave the way you want:

Clear[myF, x, y];
Do[myF[n, m][{x_, y_}] = f[[n, m]], {n, Length[f]},
 {m, Length[f[[1]]]}]
myPts[n_, m_] := pts[[n, m]];
myF[1, 1][myPts[1, 1]]

A similar method to the one Gianluca proposed could be:

f = Map[Function[{pt}, # /. {x :> pt[[1]], y :> pt[[2]]}] &, f, {2}];

a function call would then look like this (I admit this is not exactly what you want …):

f[[1, 3]][pts[[1, 3]]]

or likewise

dims = Dimensions[f];
Table[f[[n, m]][pts[[n, m]]], {n, 1, dims[[1]]}, {m, 1, dims[[2]]}]

Regards – Henrik

There is nothing wrong in generating lists of expressions and then use proper programming to calculate the results. The WL does not “insist” on a specific programming style and there are several ways of doing the required task. The best of all is to mix procedural, functional and rewrite rules programming styles so the program will be elegant, short and efficient.
IMHO, the original poster used expressions such as

f[1,1][x_,y_]:=4x

just to clarify what he meant in his original post

best

yehuda

It helped a lot, thank you all..