Replacing with values of list

It is a really simple question, but I'm a bit stuck. I have a matrix

J = ( {
{e - a y - 2 x e, -a x},
{b e y, b e x - 1 - 2 y}
} );

and a list of pairs

listS = {{0, 0}, {0, -1}, {1,
0}, {(e + a)/(e (1 + b a)), (e b - 1)/(
b a + 1)}};

And I want to replace (x,y) in J by values of listS and to get a list of four matrix. The way I do it:

J /. {x -> listS[[All, 1]], y -> listS[[All, 2]]}
J /. {x,y}-> listS

doesn't satisfy me, because in first case I get the list of four elements with the same matrix indexes in each list element, but in the second case it replace nothing at all.

• So what exactly is the desired output in this case? – Mr.Wizard May 24 '17 at 16:16
• Do you by any chance want J /. (Thread[{x, y} -> #] & /@ listS)? – jjc385 May 24 '17 at 16:25

The problem with your first approach is that it directly replaces x (and y) by a list. It seems like you rather want each of x and y replaced by a single value, and to return a list of such results. The way to do this is by supplying ReplaceAll (/.) with a list of lists of replacement rules, e.g.,

x /. {{x->1},{x->2},{x->3}}
{1, 2, 3}

In your case, you can achieve this using Threadand Map(/@) :

Thread[{x, y} -> #] & /@ listS
{{x -> 0, y -> 0}, {x -> 0, y -> -1}, {x -> 1, y -> 0}, {x -> (a + e)/((1 + a b) e), y -> (-1 + b e)/(1 + a b)}}

and then perform the replacement:

J /. (Thread[{x, y} -> #] & /@ listS)

A nice way to view the output is

MatrixForm /@ % Does this give the output you seek? f[i_] := J /. {x -> listS[[i, 1]], y -> listS[[i, 2]]}; Table[f[i], {i, Length[listS]}]

• It solves my problem too, but the solution of jjc385 does the same and is shorter. – Artem Zefirov May 24 '17 at 16:42