I do need to numerically calculate the following forms for any $x\in\mathbb{R}^n$, possibly in python:
- $x^T M^k x$, where $M\in\mathbb{R^n}$ is a PSD matrix, where $k$ can get quite large values $-$possibly up to order of hundreds. I prefer $k$ to be a real number, but it is ok if it can only be an integer, if that makes a considerable accuracy difference.
- Similarly I am interested in $x^Te^{-tM}x$ where $t$ is a non-positive real value. For case 1 I can either:
- Use the scipy.linalg.fractional_matrix_power to calculate $M^k$ and then derive $x^TM^Kx$, or
- Use scipy.linalg.svd to find SVD of $M$ as $U\Lambda U^T$ and then finally evaluate the desired value using $x^TU\Lambda^k U^Tx$.
- Finally if $k$ is integer, and again based on SVD I can calculate $\|x^TM^{k/2}\|^2$.
For case 2
- Again I can use off the shelf scipy.linalg.expm and then exponentiate the singular values of $M$
- I can do SVD for $M$ and then go with $x^TU\exp(\Lambda) U^Tx$.
- Finally since I am only interested in $x^T \exp(M) x$, and not exactly $\exp(M)$ it self, I can consider the Taylor expansion of $x^T{\rm expm}(M)x\approx \sum_{i=0}^{l} \frac{1}{i!}x^TM^ix$ for some $l$ that controls the precision, and $x^TMx$ can be calculated based on case 1.
Can anybody guide me about what is the most precise way to calculate either of these expressions, up to hopefully machine precision? Any of these methods, or they're better solutions out there? I would be happy also with references.
P.S. Not knowing if here or stackoverflow being a good place to share this question at, I will be cross-posting it on their with the same title and content.