MATLAB: 3D surface issues HELP!

3d surfacelinspacemeshmeshgrid

  • * So these are the questions… most of the variables are fixed the long equation has been dramatically simplified in my code 🙂 * *
  • | This is what mine looks like.. |
What it should look like…
This is my code…
% Q = theta
r = linspace(0,15,200);
Q = linspace(0,2*pi,200);
[r,Q] = meshgrid(r,Q);
w = 14.0591*(1-(r/15)^2)^2 + 15;
x = r.*cos(Q);
y = r.*sin(Q);
mesh(x,y,w)
What have I done wrong? Why isnt mine round, I dont think 'r' is being inputed into the 'w' equation correctly, HELP!

Best Answer

You need to vectorise your code and it will do just what you want:
r = linspace(0,15);
Q = linspace(0,2*pi);
[r,Q] = meshgrid(r,Q);
w = 14.0591*(1-(r/15).^2).^2 + 15;
x = r.*cos(Q);
y = r.*sin(Q);
mesh(x,y,w)