MATLAB: Gram schmidth of polynomial

gram-schmidtorthonormal basis

Hello All,
Can we determine ortho-normal basis vectors for polynomial functions series, like f(x) =[x, x^2, x^4…….x^100].
I tried function orth for the same but i guess it is not for matrices and not for functions.

Best Answer

Of course orth is not designed to solve that problem, since it uses linear algebra.
Nothing stops you from writing an orthognalization code. Of course, you will be unable to do so using double precision arithmetic, because you will rapidly run into numerical problems, long before you get that high. (So my own sympoly toolbox would fail quickly.)
You could do it using symbolic tools. But why? A family of orthogonal polynomials already exists in the form of the Legendre polynomials. Ok, I suppose the set you have provided does not include the zero'th order term, a constant. I'm not sure if you just decided not to do so, or if that was by choice.
Or, do you have some other weight function, than one of the standard choices?
For example, suppose you decided to use syms. I'll pick an arbitrary interval of [-1,1], since unless a weight function is used with the correct properties, OR you have a finite interval, no such orthogonalization will be possible.
For example, suppose we start with the family
syms x
n = 5;
P = x.^(1:n);
that we wish to be orthonormal on the interval [-1,1]. Start with P(1).
Q(1) = P(1);
Q(1) = Q(1)/sqrt(int(P(1)^2,[-1,1]))
Q =
[ (2^(1/2)*3^(1/2)*x)/2, 0, 0, 0, 0]
So Q(1) is properly normalized. We can test that fact.
sqrt(int(Q(1)^2,[-1,1]))
ans =
1
Now just apply Gram-Schmidt, in a loop.
for i = 2:n
Q(i) = P(i);
for j = 1:i-1
Q(i) = Q(i) - Q(j)*int(Q(i)*Q(j),[-1,1]);
end
Q(i) = Q(i)/sqrt(int(Q(i)^2,[-1,1]));
end
Which all seems pretty simple to me.
int(Q(5)^2,[-1,1])
ans =
1
vpa(Q(5),5)
ans =
18.469*x^5 - 20.521*x^3 + 4.3973*x
vpa(Q(4),5)
ans =
7.4246*x^4 - 5.3033*x^2
So an orthognal basis of the family in P. WTP? Yes, if you want to go as high as n=100, things will get messy.