Why I can't plot an implicit form of function including abs()?

2 views (last 30 days)
Hello I'm first in learning MATLAB.
I tried to plot an implicit form of function which includes abs(), but nothing shown in the figure.
Is it impossible to use fimplicit() just like the code below?
Thanks in advance!
syms y(x)
fimplicit(abs(y-x)*(1+y/x)^2==0);

Accepted Answer

John D'Errico
John D'Errico on 10 May 2020
Edited: John D'Errico on 10 May 2020
First, you are tryign to do the wrong thing here:
fimplicit(abs(y-x)*(1+y/x)^2==0);
That creates a LOGICAL result. Then you ask fimplicit to solve for the solution. You would be better to try this:
fimplicit(abs(y-x)*(1+y/x)^2);
which will still fail as I explain. But at least the latter case returns a NUMBER, not a binary result.
Can you use fimplicit on a problem like that? You have contrived a difficult case, in the sense that it is a function that is always non-negative. The ONLY place where it ever touches down to zero are the 45 degree lines x==y or x==-y.
And on either side of that line, the surface described by the function is strictly positive. So what happens is the tool simply never finds any locus of points that satisfy this expression yielding zero.
Your best chance is something like this:
syms x y
H = fcontour(abs(y-x).*(1+y./x).^2);
H.LevelList = .05;
Here we see both solution loci approximately delineated. However, if I try to make the contour level too close to zero, then fcontour will also fail.
Can you have abs in a function, and still be able to use fimplicit? Well, yes. But fimplicit is not really doing anything incredibly intelligent. In fact, fimplicit is probably just a contour plotting tool that looks for the zero contour. It does not understand your function, nor what it does. So it cannot simply see what is happening. That is easy enough for us. Computers are not so smart though.
But, to ask if you can use abs in a problem with fimplicit, as I said, yes. There is no problem. Again, as I said, do NOT set it equal to zero, as that creates a binary result and fimplicit would again probably fail.
fimplicit(abs(x - y) - 1)
fimplicit implicitly searches for zero anyway.
Remember that fimplicit is just an adaptive code that searches for the solution locus. But if you understand what it is doing, then it is easy both to come up with examples where it must fail, as well as it is easy to come up with examples where it succeeds. As you learn more about numerical methods in programming, for example numerical integration or optimization, again, you can always come up with problems that will cause those adaptive routines to fail. That is true of similar codes found in any language or environment. The more skilled was the programmer who created the codes, thus a person with better skills in both programming and numerical analysis, the more difficult it will be to find something that will confound the code. But once you fully understand the algorithms employed, you will be able to confound them. :()

More Answers (0)

Community Treasure Hunt

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

Start Hunting!