syms m1 m2 m3 B1 B2 k1 k2

%

A = [0, 0, 0, -1 / m1, 0;
    0, -B1 / m2, B1 / m2, 1 / m2, -1 / m2;
    0, B1 / m3, -(B1 + B2) / m3, 0, 1 /m3;
    k1, -k1, 0, 0, 0;
    0, k2, -k2, 0, 0]

%

B = [1/m1; 0; 0; 0; 0]

%

C = [0 0 1 0 0]
D = [0]

%

syms s

%

H = C * inv(s * eye(5) - A) * B + D