title: Difference between using a loop and multiplying using scalar
body: <p>My title may not have been properly formatted but, we took a class on plotting 3D mesh and surfaces and were taught the first method below which multiplied using scalars to obtain <code>'z'</code>. Upon searching for a solution to a problem I found another method in obtaining <code>'z'</code>. Upon plotting you get visually similar surfaces but, their directions are different hence values used.</p>
  <p>I want to know the difference between the two.</p>
  <p><strong>Method 1</strong></p>
  <pre><code>[X,Y] = meshgrid(-2:0.1:2);
  Z = X.*exp(-((X-Y.^2).^2 + Y.^2));
  mesh(X,Y,Z),xlabel('x'),ylabel('y'),zlabel('z' )
  </code></pre>
  <p><strong>Method 2</strong></p>
  <pre><code>m = 1;
  for X = -2:0.1:2
      n = 1;
      for Y = -2:0.1:2
          Z(m,n) = X.*exp(-((X-Y^2)^2 + Y^2));
          n = n + 1;
      end 
      m = m + 1;
  end 
  
  [X,Y] = meshgrid(-2:0.1:2);
  mesh(X,Y,Z),xlabel('x'),ylabel('y'),zlabel('z')
  </code></pre>