Updated to provide more details (per a suggestion in the comments). In addition, the implementation using Outer
was wrong
A simple extension of what you've written will do the trick:
Ordering[Function[x,g[x,yFixed]] /@ {1,2,3}]
or more simply,
Ordering[g[#,yFixed]& /@ {1,2,3}]
where g[#,yFixed]&
is essentially shorthand for Function[x,g[x,yFixed]]
.
The reason your original idea doesn't work is that Map
(or /@
) applies the left-hand side to each element of the right-hand in a literal fashion. For instance, the first element of the list is g[_,0][1]
. In this case, g[_,0]
gets evaluated first by plugging in _
for x
and 0
for y
. The resulting expression is then applied to 1
, yielding (4 - 4 _ + _^2)[1]
, which is a very strange expression.
Alternatively, you could use Outer
, although maybe this is overkill for this problem. On the other hand, it would allow you to do many values of y
at once, by replacing the third argument of Outer
with the list of y
's and mapping Ordering
over the result. For your example:
Ordering[Outer[g,{1,2,3},{yFixed}]]
Outer
supplies all pairs of elements---the first from the first list, and the second from the second---as inputs to g
and forms a list. If you have a list ys={0,4}
, you could do
Ordering/@ Transpose[Outer[g,{1,2,3},ys]]
Ordering[Function[x, g[x, yfixed]] /@ {1, 2, 3}]
? – Guess who it is.♦ yesterdaySlot
. :) – Guess who it is.♦ yesterday