function Control1_2( model )
% Solution to problem 2, control 1, Nov.2016
% J.M.Soler

% Set parameters
dt = 0.1;    % time interval (s)
if model=='A'
  v = 0.8;   % velocity of a (m/s)
  d = 2.0;   % distance between a and b (m)
  tf = 40;   % final time (s)
elseif model=='B'
  v = 0.25;
  d = 8.0;
  tf = 90;
elseif model=='C'
  v = 0.65;
  d = 6.0;
  tf = 70;
elseif model=='D'
  v = 0.4;
  d = 2.5;
  tf = 35;
else
  error(['ERROR: invalid model = ',model])
end

% Find requested magnitudes
t = (0:dt:tf);                  % simulation times
xa = v*t;                       % trajectory of a
ya = zeros(size(t));
xb = v*t-d*tanh(v*t/d);         % trajectory of b
yb = d*sech(v*t/d);
vxa = derivative(t,xa);         % velocities
vya = derivative(t,ya);
vxb = derivative(t,xb);
vyb = derivative(t,yb);
axa = derivative(t,vxa);        % accelerations
aya = derivative(t,vya);
axb = derivative(t,vxb);
ayb = derivative(t,vyb);
va = sqrt(vxa.^2+vya.^2);       % velocity moduli
vb = sqrt(vxb.^2+vyb.^2);
aa = sqrt(axa.^2+aya.^2);       % acceleration moduli
ab = sqrt(axb.^2+ayb.^2);
da = integral(t,va);            % traversed distaces
db = integral(t,vb);

% Plot trajectories
figure(11)
plot(xa,ya,'o',xb,yb,'o')
legend('a','b')
axis equal
grid on
xlabel('x (m)')
ylabel('y (m)')
title('Trajectories')

% Plot velocities
figure(12)
plot(t,va,t,vb)
grid on
legend('a','b')
xlabel('t (s)')
ylabel('|v| (m/s)')
title('Velocities')

% Plot accelerations
figure(13)
plot(t,aa,t,ab)
grid on
legend('a','b')
xlabel('t (s)')
ylabel('|a| (m/s^2)')
title('Accelerations')

% Plot traversed distances
figure(14)
plot(t,da,t,db)
grid on
legend('a','b')
xlabel('t (s)')
ylabel('d (m)')
title('Traversed distances')
