%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Script:           Graphs
% Description:      1D Graphs in Kinematics
% Autor:            Stefan Bracher
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Initialization -------------------------------------------
clear all
clc
clear figures

% --- Variables ------------------------------------------------
npts=1000;           % Number of Datapoints
tmax=10;           % t max
dt=tmax/double(npts-1);
t=0:dt:tmax;       % time

% Acceleration
for i=1:(npts)
    if t(i)<2
        a(i)=0;
    elseif t(i)<4
        a(i)=2;
    elseif t(i)<6
        a(i)=0;
    else 
        a(i)=-1;
    end
end


% Velocity
v(1)=0;
for i=2:(npts)
    v(i)=v(i-1)+a(i)*dt;
end
% Position
s(1)=0;
for i=2:(npts)
    s(i)=s(i-1)+v(i)*dt;
end


figure(1)
plot(t, a, '-')
axis([t(1) t(npts) (min(a)-1) (max(a)+1)])
grid on
title('a-t Graph')
xlabel('t [s]')
ylabel('a [m/s²]')


figure(2)
plot(t, v, '-')
axis([t(1) t(npts) (min(v)-1) (max(v)+1)])
grid on
title('v-t Graph')
xlabel('t [s]')
ylabel('v [m/s]')

figure(3)
plot(t, s, '-')
axis([t(1) t(npts) (min(s)-1) (max(s)+1)])
grid on
title('s-t Graph')
xlabel('t [s]')
ylabel('s [m]')
