# Gram-Schmidt orthonormalization: gramschmidt

### 5.54.5 Gram-Schmidt orthonormalization: gramschmidt

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.
  With one argument:
  - 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.

- Input:
  normal(gramschmidt([[1,1,1],[0,0,1],[0,1,0]]))
  or:
  normal(gramschmidt([[1,1,1],[0,0,1],[0,1,0]],dot))
  Output:

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

  √

  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=

  ∫

  1
  −1

  P(x) Q(x)dx

  Input:

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

  or:
  gramschmidt([1,1+x],(p,q)->integrate(p*q,x,-1,1))
  Output:

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  1

  √

  2

  ,

  1+x−1

  √

  6

  3

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦