title: Infinite While loop in Matlab
body: <p>I'm trying to write a script file in Matlab that will plot the trajectory of a ball thrown at a specific angle (a), velocity (v) and from an initial height (y0). I have the equation and want Matlab to plot the path of the ball in flight. However, I want it to only plot it until it hits the ground (y = 0). </p>
  
  <p>To do this I have used a while loop, but it seems to never satisfy the condition and just run forever. I'm sure the condition can be met after a number of iterations from x, but it just goes on for minutes, what's wrong?</p>
  
  <p>The code is as follows.</p>
  
  <pre><code>    % Trajectory Plotter with cutoff
      clear all
      close all 
      clc
  
      y0 = input('Enter a value for y0 in meters: ');
  
      if y0 &lt; 0 
          disp('Please enter a positive value for y0')
      end
  
      a = input('Enter a value for theta in degrees: ');
      g = 9.81;
      v = input('Enter a value for initial velocity in m/s: ');
  
      x = 0;
      y = y0 + x*tand(a) - (g*x.^2)/(2*(v*cosd(a))^2)
  
      while y &gt;= 0
          x = x+0.2
      end
  
      plot(x,y);
  </code></pre>
  
  <p>Apologies if this is a trivial  problem, I'm new to Matlab/programming.</p>
  
  <p>Thanks.</p>