I have an objective function of the following quadratic form:

f(\textbf{R}) = \sum_i  \textbf{y}_i^\textsf{T} \textbf{R}^\textsf{T} \textbf{P}_i \textbf{R} \textbf{y}_i -   \textbf{x}_i^\textsf{T} \textbf{P}_i \textbf{R} \textbf{y}_i -   \textbf{y}_i^\textsf{T} \textbf{R}^\textsf{T} \textbf{P}_i \textbf{x}_i +   \textbf{x}_i^\textsf{T} \textbf{P}_i \textbf{x}_i

where \textbf{P}_i is an NxN matrix (properties described below), \textbf{x}_i and \textbf{y}_i are Nx1 vectors, and \textbf{R} is an NxN rotation matrix (including reflections), s.t. \textbf{R}^\textsf{T} \textbf{R} = \textbf{I}  (identity). I would like to minimize f(\textbf{R}), given that constraint.

I would like to know how this might most efficiently be achieved in the following cases:
1. \textbf{P}_i = s\textbf{I}, s being a scalar.
2. \textbf{P}_i = \textrm{diag}\{\textbf{q}_i\}, \textbf{q}_i being an Nx1 vector.
3. \textbf{P}_i is a positive semi-definite (symmetric) matrix.

It is worth noting that if there is a specific or simpler solution for N = 3, then I'd be interested in that, though the general solution is of primary interest.

Can you help?