0
$\begingroup$

I'm having an issue with my code. I will be trying to eliminate variables from a system of simultaneous equations and just trying to plot 2 of them. In the simplest example, I am hoping the following will plot the line $y = x$:

ContourPlot[Eliminate[{x == z, z == y}, z], {x, -5, 5}, {y, -5, 5}]

But it just returns the blank square. What is the syntax for actually plotting the correct $x, y$ points that solve the equation?

$\endgroup$
3
  • 1
    $\begingroup$ Your code makes no sense. Try Eliminate[{x == z, z == y}, z] which gives y = x, which is certainly not in any form appropriate for ContourPlot. $\endgroup$ Commented Aug 9, 2021 at 0:27
  • 1
    $\begingroup$ ContourPlot[ Eliminate[{x == z, z == y}, z] // Evaluate, {x, -5, 5}, {y, -5, 5}] $\endgroup$
    – cvgmt
    Commented Aug 9, 2021 at 1:53
  • 1
    $\begingroup$ ContourPlot holds the code (does not let it evaluate) and inspects the Head[] of the code to determine what sort of contour plot will be constructed. The Head in your case is Eliminate, and it does not know what to do with it. Hence, @cvgmt's solution. $\endgroup$
    – Michael E2
    Commented Aug 9, 2021 at 4:15

1 Answer 1

1
$\begingroup$

Try this:

With[{e = Eliminate[{x == z, z == y}, z]}, 
 ContourPlot[e, {x, -5, 5}, {y, -5, 5}]]

Evaluating Trace[ContourPlot[Eliminate[{x == z, z == y}, z], {x, -5, 5}, {y, -5, 5}]] (output not shown here because it is large) shows that the Eliminate does not get evaluated inside ContourPlot.

Meanwhile, Trace[With[{e = Eliminate[{x == z, z == y}, z]}, ContourPlot[e, {x, -5, 5}, {y, -5, 5}]]] shows that e gets set to the result of Eliminate[{x == z, z == y}, z] early on in the computation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.