My graph in matlab has a blank strip in the middle

1 view (last 30 days)
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

Accepted Answer

John D'Errico
John D'Errico on 23 Jul 2014
Edited: John D'Errico on 23 Jul 2014
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.

More Answers (1)

dpb
dpb on 23 Jul 2014
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 Comments
Joseph Cheng
Joseph Cheng on 23 Jul 2014
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 on 23 Jul 2014
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.

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!