Am I plotting this function correctly?

I'm trying to make a plot using the cartesian equation, , on the interval of .
Using symbolic math and solving for y, I get the function: .
When I try to run the script file I get a plot with imaginary points plotted.
Here is the code that I use and the corresponding plot output:
clc;clear;
x=-1:0.1:1;
y=(1-x.^(2/3)).^(3/2);
plot(x,y)
Maybe I'm mistaken, but aren't I plotting within the domain of the function?
Any help would be appreciated! Thank you!

4 件のコメント

dpb
dpb 2019 年 9 月 29 日
for x<0, x^2/3 is complex.
In MATLAB, plot just plots the real part of complex values which is what you're seeing on the plot.
Daniel Smiley
Daniel Smiley 2019 年 10 月 2 日
thank you! I think I understand now. x.^(2/3) when ran in MATLAB, the fraction 2/3 is evaluated first and then applied as a power to the values of x. I thought it would work like a calculator by raising the x to the power of 2 then taking the cube root.
Stephen23
Stephen23 2019 年 10 月 2 日
dpb
dpb 2019 年 10 月 2 日
That's what you forced MATLAB to do by enclosing the fraction in parentheses...
>> x=-1;
>> x^(2/3)
ans =
-0.5000 + 0.8660i
>> x^2/3
ans =
0.3333
>>
Search for "operator precedence" in the documentation for the precise order of various operations. The exponention preceding the division is normal in every programming language I'm aware of.
The original expression is not ambiguous, however, owing to the implied parentheses in having written the exponent 2/3 in type that indicates it was the fraction that is the exponent.

回答 (0 件)

この質問は閉じられています。

製品

リリース

R2019a

質問済み:

2019 年 9 月 29 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by