(* declare what inner product we're thinking of *)
lowerbound=0;upperbound=1;
AngleBracket[f_,g_]:=Integrate[f*g,{x,lowerbound,upperbound}];

(* performs Gram-Schmidt to a list of vectors using AngleBracket's inner product *)
DoGramSchmidt[basis_]:=Fold[With[{basissofar=#1,newfn=#2},With[{
(* subtract off Σ⟨newfn, vj⟩vj. *)
orthofn=newfn-Plus@@((N[⟨newfn,#⟩]&/@basissofar)*basissofar)},
Join[basissofar,{
(* normalize the resulting difference*)
orthofn/N[Sqrt[⟨orthofn,orthofn⟩]]}]]]
(* and loop. *)&,
{},basis];

(* an example basis for an example subspace *)
basis={1,x,x^2,x^3,x^4,x^5};
(* perform Gram-Schmidt to the basis *)
orthobasis=DoGramSchmidt[basis];
(* print the before-and-after for comparison *)
{basis,orthobasis//Expand}//Transpose//MatrixForm

(* example function *)
f=Cos[x];
(* approximate f by orthonormal projection *)
fapprox=Plus@@((N[⟨f,#⟩]&/@orthobasis)*orthobasis);
(* approximate f by Taylor expansion *)
ftaylor=Normal[Series[f,{x,(lowerbound+upperbound)/2,5}]];
(* print the expressions for comparison *)
{f,fapprox//Expand,ftaylor}//MatrixForm
(* plot the expressions for comparison.
 red: original,
 green: orthonormal approximation,
  blue: Taylor approximation. *)
Plot[{f,fapprox,ftaylor},{x,lowerbound,upperbound},PlotStyle->{Red,Green,Blue}]

(* an example basis for an example subspace *)
lowerbound=-Pi;upperbound=Pi;
basis={1,Cos[x],Cos[2x],Cos[3x],Sin[x],Sin[2x],Sin[3x]};
(* perform Gram-Schmidt to the basis *)
orthobasis=DoGramSchmidt[basis];
(* print the before-and-after for comparison *)
{basis,orthobasis//Expand}//Transpose//MatrixForm
(* example function *)
f=x^3+x^2-5x+1;
(* approximate f by orthonormal projection *)
fapprox=Plus@@((N[⟨f,#⟩]&/@orthobasis)*orthobasis);
(* plot the expressions for comparison.
 red: original,
 green: orthonormal approximation. *)
Plot[{f,fapprox},{x,lowerbound,upperbound},PlotStyle->{Red,Green}]

(* example function *)
f=x^3+x^2-5x+1;
fapproxes={};
For[n=1,n<5,n++,
(* an example basis for an example subspace *)
basis=Join[{1},Table[Cos[j x],{j,1,n}],Table[Sin[j x],{j,1,n}]];
(* perform Gram-Schmidt to the basis *)
orthobasis=DoGramSchmidt[basis];
(* approximate f by orthonormal projection *)
fapproxes=Join[fapproxes,{Plus@@((N[⟨f,#⟩]&/@orthobasis)*orthobasis)}];
(* plot the expressions for comparison.
 red: original,
 green: orthonormal approximation. *)
list=Join[{f},fapproxes];
Print[Plot[list,{x,lowerbound,upperbound},Filling->{1->{Length[list]}}]]]