Weighted Euclidean inner product (source code)

= Weighted Euclidean inner product
{title2=$\langle u,v\rangle_M=u^TMv$}

A <symmetric positive-definite matrix> $M$ defines an <inner product> on real coordinate <vectors> by
$$
\langle u,v\rangle_M=u^TMv,\qquad \|u\|_M^2=u^TMu.
$$
For diagonal $M$, positive diagonal entries weight the squared coordinate errors. This is the finite-coordinate version of a <weighted inner product>; the positive-definite matrix example appears in https://people.tamu.edu/~f-narcowich/m641/m641_notes/inner_products.html[Francis Narcowich, Inner Products and Norms, standard inner products, example 8].

For $M=\operatorname{diag}(4,1)$, the squared <norm> of $(a,b)^T$ is $4a^2+b^2$. A first-coordinate error of one costs as much as a second-coordinate error of two. The <unit sphere> is the <ellipse> $4a^2+b^2=1$, and <orthogonality> means $4u_1v_1+u_2v_2=0$. Thus “closest” and “perpendicular” depend on the chosen <inner product>. The <orthogonal projection residual> example shows how this changes a best approximation.