My graph in matlab has a blank strip in the middle
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Nismeta
am 23 Jul. 2014
Kommentiert: Nismeta
am 23 Jul. 2014
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
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 23 Jul. 2014
Bearbeitet: John D'Errico
am 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.
Weitere Antworten (1)
dpb
am 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 Kommentare
Joseph Cheng
am 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;
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!