Help me about sphere ?
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163419/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163420/image.jpeg)
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.
0 个评论
回答(1 个)
Mischa Kim
2014-5-27
编辑:Mischa Kim
2014-5-27
Nguyen, use instead
z = real(sqrt(1 - x.^2 - y.^2));
to retain the real part only.
3 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!