# Quadratic form with one value changed.

I came across the following problem when trying to run a Metropolis algorithm. (It is related to computing a multivariate normal density.)

Let us have an $n\times n$ matrix $A$ of a special kind: all of its entries are equal to $r$, $0 < r < 1$, except the diagonal entries that are either $1$ or $1+ \tau^2$, for some given $\tau$.

An arbitrary real-valued vector $x$ of length $n$ is also given. The goal is, given the value of a quadratic form $x' A^{-1} x$, compute $x' B^{-1} x$, where $B$ differs from $A$ in only one diagonal position, where either $1$ is switched to $1 + \tau^2$ or vice versa.

This has to be done with minimum computational effort ($n$ is likely large).

As an example, let

$$A = \left[ \begin{array}[ccc] \\ 1 & 0.2 & 0.2 \\ 0.2 & 1 & 0.2 \\ 0.2 & 0.2 & 1.5 \end{array} \right]$$

$$x = [2 \ 5 \ 7]'$$ and $$B = \left[ \begin{array}[ccc] \\ 1 & 0.2 & 0.2 \\ 0.2 & 1.5 & 0.2 \\ 0.2 & 0.2 & 1.5 \end{array} \right]$$

Note: very easy when calculating $x'Bx$ out of $x'Ax$ but the inverse is giving me some problems.