# Struggling to apply algebra to an inner product

I'm stuck in the following problem. I feel there may be an elegant solution that's avoiding me, as it's obvious choosing $$a$$ such that $$x-ay$$ orthogonal to y will minimize $$x-ay$$, but I'm getting stuck in the algebra. Here's the problem.

let $$||\cdot||$$ be a norm on $$V$$, derived from an inner product, let $$x,y\in V$$ and suppose $$y\ne0$$. Show that the scalar $$a_0$$ that minimizes $$||x-ay||$$ is $$a_0=\langle x,y\rangle/||y||^2$$, and that $$x-a_0y$$ and $$y$$ are orthogonal.

Once I have the first part, the second part is trivial to show.

I've tried expanding $$\langle x-ay,x-ay\rangle$$, but I haven't seen any obvious solution emerge, besides being rather tedious.

Expanding $$||x-ay||^2 = \langle x-ay, x-ay\rangle$$ results in $$||x||^2 - 2a\langle x,y\rangle + a^2||y||^2,$$ which is a quadratic function of $$a$$. Since the coefficient of $$a^2$$ is positive, it has a minimum. The derivative with respect to $$a$$ is $$2a||y||^2 - 2\langle x,y\rangle,$$ which is zero when $$a = \langle x,y\rangle/||y||^2$$.