Replace – Create matrix of solution coefficients and assign 0 for empty cells

I tried to construct a matrix from the coefficients of my solution.

1; It does not work coefficient and list for me.

2; Some matrix elements are empty, so I have to assign 0 in these empty cells.
See code after sol input

clear["Global`*"]
need["VariationalMethods`"]

n = 4;
m = 0.145;

index[x, 0][t_]    = 0;
"These two initial conditions make some cells empty, so I can not create a matrix directly with matrix shape."
index[x, n + 1][t_]    = 0;

index[k, (j_)?EvenQ] = 1.7;
index[k, (j_)?OddQ] = 5;
index[k, 0] = 1;
index[k, n + 1] = 1;

ue[x_, t_, k_, n_] : =
(1/2) * Sum[Subscript[k, j]*(Index[x, j - 1]
{j, 1, n + 1}];

th[x_, t_, n_] : = (1/2) * m * Sum[Derivative[1][Index[subscript[Index[Subscript[x, j]]

lg[x_, t_, k_, n_] : = te[x, t, n] - ue[x, t, k, n];

gl[x_, t_, k_, n_] : = Expand[EulerEquations[lg[EulerEquations[lg[EulerEquations[lg[EulerEquations[lg[x, t, k, n],
table[Index[subscript[Index[Subscript[x, j]


sol = Simplify[Matrixform[Tosolve[Eq[Matrixform[Solve[eq[MatrixForm[Lösen[Gl[MatrixForm[Solve[eq[x, t, k, n], Table[Derivative[2][Index[subscript[Index[Subscript[x, j]]
{j, 1, n}]]]]rules = coefficient rules[lst[j], {Table[Derivative[2][Index[subscript[Index[Subscript[x, j]]

Choose[lstMemberQ[lstTabelle[lstMemberQ[lstTable[lstMemberQ[lstTabelle[lstMemberQ[lstTable[Derivative[2][Index[subscript[Index[Subscript[x, j]]