% Unit 2 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%=====================================
% application: force law
%=====================================
clear all
close all
clc

% experimental data
h = [2.0000, 4.0161, 5.5282, 6.5363, 7.0403, 7.0403, 6.5363, 5.5282, 4.0161, 2.0000];
t = [0,      0.2268, 0.4536, 0.6804, 0.9073, 1.1341, 1.3609, 1.5877, 1.8145, 2.0413];

% plot data
figure(1), hold on
plot(t,h,'b')

% determine velocity
[v, tv] = derivative(h,t);
plot(tv,v,'r')
xlabel('t [s]')
ylabel('h(t) [m] & v(t) [m/s]')
legend('experimental position','numerical velocity')

% determine acceleration
[a, ta] = derivative(v,tv);
figure(2), hold on
plot(ta,a,'b')
plot(ta,linspace(mean(a),mean(a),length(ta)),'r')
xlabel('t [s]')
ylabel('a [m/s^2]')
legend('numerical acceleration','mean acceleration')
