why my plot is not correct?
2 ビュー (過去 30 日間)
古いコメントを表示
here is my code
x = -5:0.1:5
y = x.^(1/3)
plot(x,y)
回答 (2 件)
Paul
2021 年 4 月 11 日
If you're looking for a plot with odd symmetry, try:
plot(x,nthroot(x,3)) % check doc nthroot for details
0 件のコメント
DGM
2021 年 4 月 11 日
I'm not sure what you intend the correct number to be. You're doing the cube root of negative numbers. They're going to be complex.
By default, plot() will only plot the real component of complex inputs. If you're expecting the plot to be symmetrical, consider plotting abs(y) to get the magnitude of the complex-valued region.
x = -5:0.1:5;
y = x.^(1/3);
h1=plot(x,real(y)); hold on
h2=plot(x,imag(y));
h3=plot(x,abs(y));
legend([h1,h2,h3],'real','imaginary','magnitude','location','southeast')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/579742/image.png)
2 件のコメント
DGM
2021 年 4 月 11 日
You probably want Paul's answer below. nthroot() calculates the real root, whereas power() or .^ calculates the complex root. The web docs include such an example.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!