# RepeatedReplace (//.) not working as expected within an expression in a graph

I'm plotting a tangent line to a region and, depending when I evaluate it, I get inconsistent results. I want to use the first way of doing things for flexibility but it doesn't seem to be working. What is going wrong?

The set up code is:

mu1 = -1.0; mu2 = 1.0; ss1 = 1; ss2 = 4; cov = 1;
bivModel =
MultinormalDistribution[{mu1, mu2}, {{ss1, cov}, {cov, ss2}}]
myFun[x_, y_] := PDF[bivModel, {x, y}];
a = -2.7; b = 1.6;
yVec = D[myFun[x, y], y];
xVec = D[myFun[x, y], x]


Then when I create a graph:

Show[RegionPlot[
PDF[bivModel, {x, y}] >= contourval, {x, -7, 3}, {y, -4, 7}],
Plot[-(xVec //. {x -> a, y -> b})/(yVec //. {x -> a, y -> b})*(x -
a) + b, {x, -7, 3}], Graphics[Point[{a, b}]]]


I get this weird thing:

But then if I perform the simplification that I expect to occur within the expression I get what I am expecting. Typing:

-(xVec //. {x -> a, y -> b})/(yVec //. {x -> a, y -> b})*(x -
a) + b


gives

1.6 + 3.21739 (2.7 + x)

And substituting this back in the above gives:

Show[RegionPlot[
PDF[bivModel, {x, y}] >= contourval, {x, -7, 3}, {y, -4, 7}],
Plot[1.6 + 3.2173913043478266 (2.7 + x), {x, -7, 3}],
Graphics[Point[{a, b}]]]


Running this gives the following figure that I was expecting (and which is correct).

Why is the first expression (using //.) not working?

• Because of how Plot evaluates its arguments. Try wrapping the first argument with Evaluate – mmeent Dec 5 '18 at 16:47
• This works, but I have a more complicated instance where it does not seem to be working, so will edit my original question to include it. – GerardF123 Dec 5 '18 at 17:04

Plot[-(xVec[a,b])/(yVec[a,b])*(x -
`