function swit=switch2(t,finaltime)
% swit = a*t;
step1=finaltime/4.0;
step2=3.0.*finaltime/4;

%from 0 to finaltime/4:                   A x^2
%from finaltime/4 to 3*finaltime*4:       B x + C
%from 3*finaltime/4 to finaltime:         finalmove - (x-finaltime)^2

%B*finaltime/2+2 A*(finaltime/4)^2=finalmove
%B=A*finaltime/2
%B=(finalmove-A*finaltime^2/8)*2/finaltime
%A=2*B/finaltime
%B=(finalmove-2**finaltime^2/8)*2/finaltime

B1=4/3/finaltime;
A1=2*B1/finaltime;
C1=-A1*(finaltime^2/16);

%fprintf('\t\t%g.',t<=step1,step2 >= t & t > step1,finaltime >= t & t > step2,t > finaltime)
%fprintf('\n')

if t <= step1 
  y=A1.*t.*t;

elseif step2 >= t & t > step1
  y=B1*t+C1;
elseif finaltime >= t & t > step2

  y=1-A1.*(t-finaltime).*(t-finaltime);

end;

swit=y;

