%% Problem 6

% The trajectory (x,z coords)
x = 150*sin(0.487*t-0.921-0.933*tanh((t-10)/4));
z = 150*(1-cos(0.487*t-0.921-0.933*tanh((t-10)/4)));

%
%% Plot Trajectory

figure
fplot(x, z, [0,17]);
title('Trajectory as a Function of Time');
xlabel('x') ;
ylabel('z');

%
%% Plot Speed

vx = diff(x,t);
vz = diff(z,t);
V = sqrt(vx^2+vz^2);
figure
fplot(t,V,[0,17]);
title('Speed as a Function of Time')
xlabel('Time (s)') 
ylabel('Speed')

%
%% Plot Acceleration components

ax = diff(vx,t); az = diff(vz,t);
% Find unit vectors tangent and normal to the path
tangent = [vx,vz]/V;
normal = [-vz,vx]/V; % choose the sign of normal to make an positive
% Find the normal and tangential components by projection
at = dot([ax,az],tangent); 
an = dot([ax,az],normal);
figure
fplot(at,[0,17])
hold on
fplot(an,[0,17])
title('Acceleration (n,t) as a Function of Time')
xlabel('Time (s)') 
ylabel('Acceleration')
legend({'Tangential Component','Normal Component'},'Location','north')

%
%% Plot load factor

lf = normal(2) + an/9.81;
figure
fplot(lf,[0,17])
title('Load factor as a Function of Time')
xlabel('Time (s)') 
ylabel('Load Factor')