I am unsure about how to do a plot (graph) of an implicit function in MATLAB. Let us say a have a two-variable polynomial P
and an implicit function (not solvable explicitly) P(x,y)=0
. How do I plot the latter graph in the x-y coordinate system (with a grid)?
I tried to use the contour on z=P(x,y)
, but it gives me level curves at several levels that MATLAB chooses. I wont just the one level at z=0
.
Luckily, MATLAB contains implicit function plotting and the command is fimplicit, with appropriate option for specifying intervals for the variables etc. So, if we want to plot the implicit graph of P(x,y)=0, the way to do it is as follows (this is over ML favorite interval [-5 5]x[-5 5], there is an option for specifying other rectangles...):
P=@(x,y) P(x,y);
fimplicit(P)
grid
This will plot the graph of P(x,y)=0 with a grid. Very easy and elegant.