Project $x$ orthogonally onto $v$: is the projection $p$ the average of $x$? I have made a simple Freemat script as the following:


x = [150;150;128;128;121;119;115;112;105;42]
v = [1;1;1;1;1;1;1;1;1;1]

function p = project(x)
c = dot(x,v)/dot(v,v)
p = c*v

mean(x)


When I calculate the projection of $x$ onto $v$, $p$, I get that the entries in $p$ all are equal to the average entry of $x$. I made this in the context of statistics, and so I do not think that is a coincident.
I was wondering if anyone could help me understand why this is the case; I would be very grateful.
 A: Projecting onto $v=[1;1;1;1;....]$ will always product a vector that is a scalar multiple of $v$, so all the entries of the projection will be equal.
Second, the average of a vector $x$ of dimension $N$ is $\frac {x \circ v} N$ (using $\circ$ for dot product).  So we wonder if the projection's entries are equal to that.
The projection $p$ has two defining properties$^{[1]}$:


*

*it is a multiple of $v$, so $p = cv$

*it is orthogonal to $x - p$, so $p \circ (x - p) = 0$.


So we wish to see if the averages are equal:
$$\frac {x \circ v} N = \frac {p \circ v} N$$
Multiply by N:
$$x \circ v= p \circ v$$
Multiply by c:
$$x \circ cv = p \circ cv$$
Apply bullet 1:
$$x \circ p = p \circ p$$
And that is the property of bullet 2.  That is a nice observation you have found, finding the average by projecting onto a vector of ones.

[1] I lied a little bit, $c = 0, p = 0$ always satisfies this definition, so you have to specify the nontrivial solution if there is one.  It's fine here though since we don't need that part of the definition.
