function Control1_2(version)
% Solution to problem 2, Computacion I, 2017/11/03
% J.M.Soler, Oct.2017

% Set parameters
if version=='A'
  v = 1.5;
  d = 5.0;
  p0 = -9;
  tf = 60;
elseif version=='B'
  v = 0.5;
  d = 3.0;
  p0 = -2;
  tf = 24;
elseif version=='C'
  v = 1.2;
  d = 1.5;
  p0 = -6;
  tf = 15;
elseif version=='D'
  v = 2.0;
  d = 1.0;
  p0 = -5;
  tf = 5;
end
dt = 0.05;

% Find trajectory
t = 0:dt:tf;
f = p0+v*t/d;
g = f+sqrt(f.^2+1);
x = d*log(g);
y = 0.5*d*(g+1./g);

% Find velocity and acceleration
vx = derivative(t,x);
vy = derivative(t,y);
ax = derivative(t,vx);
ay = derivative(t,vy);

% Plot trajectory
figure(1)
plot(x,y)
xlabel('x (m)')
ylabel('y (m)')
axis equal
grid on

% Plot velocity
vmod = sqrt(vx.^2+vy.^2);
figure(2)
plot(t,vmod)
xlabel('t (s)')
ylabel('|v| (m/s)')
grid on

% Plot acceleration
figure(3)
plot(t,sqrt(ax.^2+ay.^2))
xlabel('t (s)')
ylabel('|a| (m/s^2)')
grid on

% Plot travelled distance
dist = integral(t,vmod);
figure(4)
plot(t,dist)
xlabel('t (s)')
ylabel('distance (m)')
grid on

end