function[A B C] = getLinearModel(version, vehicle, Ux) % xDot = A* x + B* delta + C* k

Cf = vehicle.Cf;
Cr = vehicle.Cr;
m = vehicle.m;
a = vehicle.a;
b = vehicle.b;
Iz = vehicle.Iz;

switch version

      case 1 % x = [ecg dpsi r beta] - all at center of gravity 
          A =[0  Ux  0                         Ux;
              0  0   1                         0;
              0  0   -(a^2*Cf+b^2*Cr)/(Ux*Iz)  (b*Cr-a*Cf)/Iz;
              0  0   (b*Cr-a*Cf)/(m*Ux^2)-1    (-(Cf+Cr))/(m*Ux)];
          B = [0;  0;  a*Cf/Iz;  Cf/(m*Ux)];
          C = [0; -Ux; 0; 0];

    case 2
        % x = [era dpsi r beta] - all at rear axle
        A = [0  Ux  0                         Ux;
             0  0   1                         0;
             0  0   -(a*(a+b)*Cf)/(Ux*Iz)     (b*Cr-a*Cf)/Iz;
             0  0   (-(a+b)*Cf)/(m*Ux^2)-1    (-(Cf+Cr))/(m*Ux)];
        B = [0; 0;  a*Cf/Iz;  Cf/(m*Ux)];        
        C = [0; -Ux; 0; 0];    
        % from CG to RA
        A(4,:) = A(4,:) - b/Ux*A(3,:);
        B(4) = B(4) - b / Ux * B(3);

        otherwise error('unimplemented version') 
end

end