why my plot is not correct?

조회 수: 2 (최근 30일)
wenchong chen
wenchong chen 2021년 4월 11일
댓글: DGM 2021년 4월 11일
here is my code
x = -5:0.1:5
y = x.^(1/3)
plot(x,y)
  댓글 수: 2
wenchong chen
wenchong chen 2021년 4월 11일
it is working, but it is giving me wrong number
wenchong chen
wenchong chen 2021년 4월 11일
also there is a Warning: Imaginary parts of complex X and/or Y arguments ignored.

댓글을 달려면 로그인하십시오.

답변 (2개)

Paul
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

DGM
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')
  댓글 수: 2
wenchong chen
wenchong chen 2021년 4월 11일
the^1/3 of negative numbers should be negative right? why both negative and positive side are both positive number?
DGM
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by