I have this code to draw haft of sphere x^2 + y^2 + z^2 = 1, z>0. but it have error. help me to fix it. thanks very much.

답변 (1개)

Mischa Kim
Mischa Kim 2014년 5월 27일
편집: Mischa Kim 2014년 5월 27일

1 개 추천

Nguyen, use instead
z = real(sqrt(1 - x.^2 - y.^2));
to retain the real part only.

댓글 수: 3

Nguyen Trong Nhan
Nguyen Trong Nhan 2014년 5월 27일
편집: Nguyen Trong Nhan 2014년 5월 27일
oh thank. but why I have to use real(). these are positive numbers so the square root of them are also the real number, why does it appear complex number here ?
Mischa Kim
Mischa Kim 2014년 5월 27일
편집: Mischa Kim 2014년 5월 27일
In a perfect world, yes. However, in numerical computations zero is not always (exactly) equal to zero. Check out this answer for reference. If you remove the semi-colon from
z = sqrt(1 - x.^2 - y.^2)
you'll notice that there are small non-zero imaginary parts.
Nguyen Trong Nhan
Nguyen Trong Nhan 2014년 5월 27일
ah Mischa Kim, could you explain me when I need to use the eval and double funtions in matlab ?

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

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

태그

질문:

2014년 5월 27일

댓글:

2014년 5월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by