I would like to embed some answer boxes as part of a matrix and am wondering if this can be done?

For example, if I want students to enter the full matrix as their solutions, I've managed to get the following to work:

\{"\(P = \)".$PP->ans_array(2)\}

For a second part, the answer is a diagonal matrix. Instead of entering a large number of zeros, I've created a multianswer checker (called DD say) and attempted to create a partially completed matrix with the zeros filled in using a similar logic to the previous part. So students only have to enter the diagonal entries

\{"\(D = \begin{bmatrix}

".$DD->ans_rule(2)".&0&0&0&0&0\\

0&".$DD->ans_rule(2)."&0&0&0&0\\

0&0&".$DD->ans_rule(2)."&0&0&0\\

0&0&0,".$DD->ans_rule(2)."&0&0\\

0&0&0&0&".$DD->ans_rule(2)."&0\\

0&0&0&0&0&".$DD->ans_rule(2)."\\

\end{bmatrix}\)"\}

However, this resulted in errors and I have been unable to resolve them. Suggestions on how to resolve this or alternative ways to approach this problem are welcomed.

Thank you very much for your help.

Regards,

Thomas

Thomas