title: Problems with Matlab script to numerically solve projectile motion
body: <p>currently I have an assignment to write a Matlab script to numerically solve the problem of a cannonball fired from a variety of angles, both with and without air friction. Of course, I'm trying to think on how to solve the air friction component, but first I need to create the model without air friction, and I cannot figure out for the life of me how it's breaking down. Here's my code:</p>
  
  <pre><code>clc;
  clear all;
  close all;
  
  % Setting initial conditions such as angle, number of sampling intervals,
  % initial x- and y-positions, etc.
  N_points=10000;
  total_time=200;
  angle_initial=20;
  gravity_initial=9.81;
  velocity_initial=700;
  y_initial=0;
  x_initial=0;
  
  % Set time vector, x-position and y-position vectors, their initial values,
  % and sampling interval.
  
  delta_t=total_time/N_points;
  y=zeros(N_points,1);
  x=zeros(N_points,1);
  time=zeros(N_points,1);
  y(1)=y_initial;
  x(1)=x_initial;
  
  %Begin loop to actually calculate y-position through time.
  %
  
  for step=1:N_points-1
      time(step+1)=time(step)+delta_t;
      y(step+1)=y(step)+((-gravity_initial*sind(angle_initial)*time(step+1)+velocity_initial*sind(angle_initial))*delta_t);
  end
  
  % Find all values of y-position vector less than zero and eliminate them
  % from vector, thus giving us only points before the projectile 'hits' the
  % ground.
  
  a_1=find(y&lt;0);
  r_1=[a_1];
  y(r_1)=[];
  b_1=length(y)
  
  %Create x-position vector starting from zero to maximum possible range of
  %projectile, separated into equal intervals corresponding to number of
  %positive elements in the y-position vector. This way, the x- and y-vectors
  %will match when they are plotted together.
  x=linspace(0,((velocity_initial^(2))/gravity_initial)*sind(2*angle_initial),b_1);
  
  %plot x- and y-position vectors.
  plot(x,y,'r')
  </code></pre>
  
  <p>I can't figure out why the function is 'blowing up' as it were; when this code is run, the range for the projectile is correct, however the height is not. I really cannot see where I'm going wrong here; I have looked through many examples and other things online, and no matter what variation I try, they all exhibit a trajectory height that is much too high. Could anyone provide a clue as to where I'm going wrong?</p>