Given
expr = u == a1 + a2 x + a3 y;
and
uRep = {u1, u2, u3};
xyRep = {{x1, y1}, {x2, y2}, {x3, y3}};
I'd like to generate 3 equations
{u1 == a1 + a2 x1 + a3 y1, u2 == a1 + a2 x2 + a3 y2, u3 == a1 + a2 x3 + a3 y3}
By replacing u
with u1,u2,u3
at a time, and at same time, replace x
with x1,x2,x3
and the same for y
Currently I do this using MapThread
with explicit Function
like this:
MapThread[Function[{z1, z2}, eq1 /. {u -> z1, x -> z2[[1]], y -> z2[[2]]}], {uRep, xyRep}]
But I was wondering what the syntax would be do it using pure function. I tried
MapThread[eq1 /. {u -> #1[[1]], x -> #2[[1]], y -> #2[[2]]} &, {uRepl, xyRepl}]
eq1 /. {u -> #1[[1]], x -> #2[[1]], y -> #2[[2]]} & @@@ {uRepl, xyRepl}
and few others. They all produce errors due to wrong slot #
mapping.
I am happy with the Function
solution, but was wondering what the syntax will be using pure function. (I looked at many related questions, but could not find solution to apply for this case, I am sure I missed something)