# Plot Expression returned from Function

Suppose we have a function that does something with its parameters, and then returns an expression containing an equality. I want to then use that expression in (Contour)Plot to visualize it. The returned expression is correct, but plotting does not work - ContourPlot appears to evaluate something else and does not draw anything. I have tried Defer and Hold*, without any change.

The actual use case is a bit more involved, but a minimum working example is this:

ellipse[a_, b_, c_] := a x^2 + b y^2 == c^2;
(* does not work *)
ContourPlot[ellipse[1, 0.42, 3], {x, -10, 10}, {y, -10, 10}]

(* manually transfer the expression - works *)
Print[ellipse[1, 0.42, 3]]
ContourPlot[x^2 + 0.42 y^2 == 9, {x, -10, 10}, {y, -10, 10}]


I have frequently run into similar problems with Plot, but this time my usual workaround of just unrolling the function manually would be very awkward, hence the question.

• Another way ContourPlot[ a x^2 + b y^2 == c^2 /. Thread[{a, b, c} -> {1, 0.42, 3}] // Evaluate, {x, -10, 10}, {y, -10, 10}] – cvgmt Sep 11 at 11:35

ellipse1[a_, b_, c_] := a x^2 + b y^2 == c^2;
ContourPlot[Evaluate[ellipse1[1, 0.42, 3]], {x, -10, 10}, {y, -10, 10}]


or more explicitly as suggested by @Kuba

ellipse1[a_, b_, c_, x_, y_] := a x^2 + b y^2 == c^2;
ContourPlot[Evaluate[ellipse1[1, 0.42, 3, x,y]], {x, -10, 10}, {y, -10, 10}]

• Huh. I tried that too, and it did not work either. But it works in the example... Are there any caveats that I might have hit? – Martok Sep 10 at 13:34
• It won't work if x or y have values @martok so you can define it as a function of five variables. – Kuba Sep 10 at 13:37
• Maybe that was it. I did try a lot of things without a Clear in between... – Martok Sep 10 at 13:54

I' m not quite sure of the details, but apparently you cannot define a function with an equality. A solution to your problem may be writing in the following way:

ellipse[a_, b_, c_] := a x^2 + b y^2 - c^2;
ContourPlot[ellipse[1, 0.42, 3] == 0, {x, -10, 10}, {y, -10, 10}];