n = 4

A = diag(ones(n-1, 1), 1) + diag(ones(n-1,1),-1) + diag([-2*ones(n-1, 1);-1])

M = diag([1,2,3,4]);

A = inv(M) * A

B = sqrtm(-A)

t=2

x0 = [.2; .3; .7; .1]

v0 = [1; 2; 3; 4]

cos(t * B) * x0 + inv(B) * sin(t * B) * v0