Hello Yi,
Let us consider the function, f(Q) = ||Q'AQ -B||f ^2 (squared frobenius norm).
The Euclidean gradient is = A' Q S + A Q S' where S = 2(Q'AQ -B). (Checked)
Now, the Euclidean Hessian operator along a direction Z (we require the directional derivative of the Euclidean gradient along the direction Z) is given systematically using the Chain rule. Below is the formula
Euclidean Hess [Z] = A'ZS + A'Q S_star + AZS' + AQS_star' (Checked)
where S = 2(Q'AQ -B) and S_star = 2(Z'AQ + Q'AZ).
Do check this out and let us know if this sounds okay. Once formalized, you can use tools like 'checkgradient' and 'checkhessian' to see if this works out.
Regards,
BM