# How do I graph the negative portion of a square root plot?

10 views (last 30 days)

Show older comments

### Answers (1)

John D'Errico
on 9 Apr 2024

Edited: John D'Errico
on 17 Apr 2024

Since in reality, you have what is called an implicit function, we want to use fimplicit. I might do it like this:

fun = @(x,y) (1 - 3.*nthroot(x,3).^2 + 3.*nthroot(x,3).^4 - x.^2) - y.^2;

That is, you will get the negative branch of the curve by squaring the square root. fimplicit does the heavy lifting for you here.

fimplicit(fun,[-1,1,-1,1])

grid on

xlabel 'X'

ylabel 'Y'

Note my use of nthroot protects me from having problems when x is negative. This avoids creating complex numbers. For example, the real cube root of -2 is

nthroot(-0.5,3)

Therefore, the real 2/3 power of -2 can be found by squaring that result.

nthroot(-0.5,3).^2

The problem of course is if you simply use direct fractional powers, then MATLAB will return ONE of the solutions, but it will choose by default a complex solution for that fractional power. In fact, there are multiple fractional powers we must worry about as solutions. This is only one of them:

(-0.5).^(2/3)

I do something similar to deal with the 4/3 power of x. As well, squaring both sides allows fimplicit to plot all 4 branches, for both positive and negative x, as well as positive and negative y.

A bit tricky I'll admit, but, it works, and works correctly, because it deals properly with those nasty fractional powers.

fimplicit is a tremendously useful tool when used carefully.

##### 0 Comments

### See Also

### Categories

### Products

### Community Treasure Hunt

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

Start Hunting!