### 15.6.5 Gram-Schmidt orthonormalization

The gramschmidt command uses the Gram-Schmidt procedure to find an orthonormal set of vectors with the same span as a given set.

- gramschmidt takes one or two arguments:
  - A, a matrix viewed as a list of row vectors or a list of elements that is a basis of a vector subspace.
  - f, a function that defines a scalar product on this vector space. If A is a matrix, then this is optional, and by default will be the standard scalar product.
- gramschmidt(A) or gramschmidt(L,f) returns an orthonormal basis for this scalar product.

#### Examples

normal(gramschmidt([[1,1,1],[0,0,1],[0,1,0]]))

or:

normal(gramschmidt([[1,1,1],[0,0,1],[0,1,0]],dot))

⎡
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎣

√

3

3

√

3

3

√

3

3

−

√

6

6

−

√

6

6

√

6

3

−

√

2

2

√

2

2

0

⎤
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎦

Define a scalar product on the vector space of polynomials by P· Q=∫−11P(x) Q(x)d x. Then:

p_scal(p,q):=integrate(p*q,x,-1,1):; gramschmidt([1,1+x],p_scal)

⎡
⎢
⎢
⎢
⎢
⎢
⎣

1

√

2

,

1+x−1

√

6

3

⎤
⎥
⎥
⎥
⎥
⎥
⎦