My graph in matlab has a blank strip in the middle

1 次查看(过去 30 天)
i graphed the following
if true
% code
end[x,y]=meshgrid(-1:.01:1, -1:.01:1);
a = .619211.*x.^2;
b = (53913.*x.^8.*y.^2 + 2560.*x.^6);
c = 232.192.*(b).^1/2;
d = (c - 53913.*x.^4.*y).^1/3;
e = a./d;
f = (53913.*x.^8.*y.^2 + 2560.*x.^6).^1/2;
g = 232.192.*f;
h = (g - (53913.*x.^4.*y));
i = .0011982.*[(h).^1/3];
z = e - i;
surf(x,y,z);shading interp
and now my graph has a strip running through the middle that is blank. how do i get rid of it/fix it

采纳的回答

John D'Errico
John D'Errico 2014-7-23
编辑:John D'Errico 2014-7-23
dpb is close, but not quite there.
The problem is when x == 0. Look at your code, line by line, thinking about what happens. (This is how you should debug these issues, and it took me far less time to resolve the issue than it took me to write this response.)
When x == 0, we see that a == 0.
Likewise, when x == 0, b == 0, and therefore c == 0.
And if you look at d, clearly when both c and x are zero, it too will be zero.
So now look at e. What is 0/0? NaN. And NaNs are like rabbits - they propagate.
Therefore, when x == 0, you get z == 0 along that line.
The trivial fix is to avoid having x == 0. So instead of having a spacing of 0.01, which gives you an odd (201) number of points over the interval [-1,1], use exactly 200 points.
[x,y]=meshgrid(linspace(-1,1,200));
The disfiguring line of NaNs will now be gone.

更多回答(1 个)

dpb
dpb 2014-7-23
z(isnan(z))=0;
surf(x,y,z)
I didn't look to see which term precisely causes the problem but you've got a numerical issue somewhere that's giving a row of nan for y=0 I believe it is.
  2 个评论
Joseph Cheng
Joseph Cheng 2014-7-23
I think its is actually when x=0 is where it Nan. If we go back to your original question. and look where these equations come from
http://www.mathworks.com/matlabcentral/answers/uploaded_files/15756/doc1.pdf there are the equations shown when x~=0. Are there modifications to the equation for when x=0? or specific equations for when x does = 0;
Nismeta
Nismeta 2014-7-23
Here is the equation i used for this graph. it is the first z = one. i found this equation when i scrolled down the page. i have tried fixing all the numerical errors and i can't see any new ones.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by