a) Let $a_{n}\rightarrow 0$ and $M=\{x\in \ell^{2}:\sum a_{n}x_{n}=0\}$. Show that the subspace $M$ of $\ell^{2}$ is closed or dense according as $% \{a_{n}\}\in \ell^{2}$ or $\{a_{n}\}\notin \ell^{2}$.
b) Let $g$ be any positive measurable function on $[0,1]$. Let $$N=\left\{f\in L^{2}([0,1]):\int_{0}^{1}f(x)g(x)dx=0\right\}$$ Prove that $N$ is closed or dense in $L^{2}([0,1])$ according as $g\in L^{2}([0,1])$ or $g\notin L^{2}([0,1])$.
Several special cases of this have appeared here. I am trying to consolidate these. I have provided an answer but my answer is probably not the best. I would look forward to comments, alternate proofs and generalizations.
For a) take $x\in l^{0}$ (the space of finitely non-zero sequences). Consider $x-c_{n}x^{(n)}$ where $x_{j}^{(n)}=\frac{a_{j}}{b_{n}}$ for $j\leq n$ and $0$ for $j>n,c_{n}=-\frac{\sum_{j=1}^{n}a_{j}x_{j}}{% \sum_{j=1}^{n}a_{j}^{2}}$ and $b_{n}=\sqrt{\sum_{j=1}^{n}a_{j}^{2}}$. Note that $\left\Vert x^{(n)}\right\Vert =1$ for each $n$ and $c_{n}\rightarrow 0$ if $\{a_{n}\}\notin l^{2}$. Hence $M$ is dense in this case. If $\{a_{n}\}\in l^{2}$ then $M$ is the orthogonal complement of $\{a_{n}\}$. hence it is closed.
For b) first observe that any $f\in L^{2}([0,1])$ can be approximated by a $h\in L^{2}([0,1])$ such that $\int_{0}^{1}\left\vert h(x)g(x)\right\vert dx<\infty $. [ Take $h=fI_{\{|fg|\leq n\}}$ ]. Now consider $% h-c_{n}\frac{gI_{\{|g|\leq n\}}}{b_{n}}$ where $b_{n}=\sqrt{\int g(x)^{2}I_{\{|g|\leq n\}}(x)dx}$ and $c_{n}=-b_{n}\frac{\int_{0}^{1}h(x)g(x)dx}{\int_{0}^{1}g^{2}I_{\{|g|\leq n\}}dx}=% \frac{\int_{0}^{1}h(x)g(x)dx}{\sqrt{\int_{0}^{1}g^{2}I_{% \{|g|\leq n\}}dx}}$. Note that $c_{n}\rightarrow 0$ if $g\notin L^{2}([0,1])$ and that $\frac{gI_{\{|g|\leq n\}}}{b_{n}}$ has norm $1$ for each $n$. The proof is completed as in a).