%% we are solving y''=-g  i.e  free fall motion
y0=[500,15];  % we start from the hight of 500 m  and our initial velocity is 15
timespan=[0,13]; % free fall for duration of  13 seconds
% try to flip initial velocity and compare the speed at  ground hit time

% independent variable x is time in our case

Npoints=10; % 10 steps is too few fro Euler's method
[time,y] = odeeuler(@free_fall_forces, timespan, y0, Npoints);

g=9.8;
yanalytical=y0(1) + y0(2)*time - g/2*time.^2;
vanalytical=y0(2) - g*time;

subplot(2,1,1);
plot(time, y(:,1), '-', time, yanalytical, 'r-');
legend('numerical','analytical');
xlabel('time');
ylabel('y-position');
title('position vs time');
grid on;

subplot(2,1,2);
plot(time, y(:,2), '-', time, vanalytical, 'r-');
legend('numerical','analytical');
xlabel('time');
ylabel('y-velocity');
title('velocity vs time');
grid on;

