k1=1000;
k2=2000;
k3=3000;
m1=1;m2=2;alpha=1;
beta=0.005;
M=[m1,0;0,m2];
K=[k1+k2,-k2;-k2,k2+k3];
n=size(M,1);
C=alpha*M+beta*K;
ssA=[zeros(n),eye(n);-M\K,-M\C];
ssB=[C,M;M,zeros(n)]\[eye(n);zeros(n)];
%ssB=[zeros(n),inv(M);inv(M),-inv(M)^2]*[eye(n);zeros(n)];
ssC=[-M\K,-M\C];
ssD=inv(M);
t=0:0.01:2;
f1=2*exp(sin(10*t));
f2=5*atan(cos(5*t)+0.2*t);
u=[f1;f2];
sys=ss(ssA,ssB,ssC,ssD);
x0=zeros(2*n,1);
y=lsim(sys,u,t);
subplot(3,1,1)
plot(t,f1,t,f2)
subplot(3,1,2)
plot(t,y(:,1))
subplot(3,1,3)
plot(t,y(:,2))