2d plot of a non-linear equation

120 views (last 30 days)
How do I create a 2D plot of a two variable expression,say 1=y^5+y*x+x^2?
I am looking for some sort of Matlab function that simply plots the values of x and y which fullfills the expression. The approach should work for any two variable expression.

Accepted Answer

Walter Roberson
Walter Roberson on 24 Mar 2021
f = @(x,y) x + y.^2 - 0.5;

More Answers (2)

John D'Errico
John D'Errico on 24 Mar 2021
Edited: John D'Errico on 24 Mar 2021
Walter has already told you how to plot it. But so you can learn how to find that for yourself, learn to use lookfor.
The trick is to know this is called an IMPLICIT FUNCTION. And therefore, you might look for something in MATLAB to handle implicit functions. I tried this in MATLAB, and this is what it told me:
>> lookfor implicit
ode15i - Solve fully implicit differential equations, variable order method.
iburgersode - Burgers' equation solved as implicit ODE system
weissinger - Evaluate the residual of the Weissinger implicit ODE
fimplicit - Plot implicit function
fimplicit3 - Plot implicit surface
imex - Class for representing implicit-explicit schemes.
normal - Normal vector to an implicit surface represented by a CHEBFUN3.
bounds - Adds implicit bounds on variables.
bounds - Adds implicit bounds on variables.
Clearly we are not interested in the first 3 of those candidates. But fimplicit or fimplicit3 might be really valuable. You might now read the help for fimplicit and fimplicit3. I bet they would be useful.
Ok, but suppose you had no clue that this is called an implcit function in mathematics?
Now you might do your detective work differently. You want to plot something, and you want to plot a function, allowing MATLAB to do all the work for you. That would normally start with fplot. But fplot cannot handle such a problem.
But if I look at the help for fplot, at the bottom, there is always a see also line.
>> help fplot
See also fplot3, fsurf, fcontour, fimplicit, plot, function_handle.
And there I see a list of functions that you may also be interested in. Does fimplicit pop up there?
Or for a third way, if you think that fplot is something that MAY be helpful, where does fplot live?
>> which fplot
So it lives with a variety of graphics utilities. Specifically, in the graphics/function directory.
>> help graphics/function
Contents of function:
fcontour - Plot function contour lines
fimplicit - Plot implicit function
fimplicit3 - Plot implicit surface
fmesh - Plot 3-D mesh
fplot - Plot 2-D function
fplot3 - Plot 3-D parametric curve
fsurf - Plot 3-D surface
matlab - is a package.
Again, there we see a line for fimplicit.
Now you would read the help for fimplicit, perhaps best done by
doc fimplicit
And there you will find a function to do exactly what you need.
In all of your searches, if you see a function that you do not know what it does, READ THE HELP FOR IT. And while it may not do what you need right now, tomorrow you might remember what you saw as something useful for your problem then.

Gurra on 24 Mar 2021
@Walter Roberson and @John D'Errico, thanks for your answers. That's all I needed to know.
  1 Comment
John D'Errico
John D'Errico on 24 Mar 2021
Please learn to use comments instead of an answer.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by