How do I graph the negative portion of a square root plot?
13 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1665071/image.png)
I would appreciate any help possible in understanding how to get this code to graph the portion of each y function shown that comes from -1 to 0. As can be seen the portion shown for each y function graphs the part from 0 to 1 but not -1 to 0.
回答(1 个)
John D'Errico
2024-4-9
编辑:John D'Errico
2024-4-17
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 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!