Gram schmidth of polynomial

10 views (last 30 days)
Yashika
Yashika on 11 Feb 2019
Commented: John D'Errico on 12 Feb 2019
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.

Accepted Answer

John D'Errico
John D'Errico on 11 Feb 2019
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.
  2 Comments
Yashika
Yashika on 12 Feb 2019
Actually my weighting function was different (includes some complex algebra), but i tried your code for my question and it worked, Thank you.
John D'Errico
John D'Errico on 12 Feb 2019
I wondered if you had some other weight function in there, as otherwise, you would just be using a traditional family of orthognal polynomials, which are easily generated directly.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!