I know the Gram-Schmidt orthogonalization generates an orthonormal basis from an arbitrary basis. I need help with:

Write a program that inputs a list $\{b_1,\dotsc,b_n\}$ of linearly independent vectors and an inner proudct and outputs a list of orthonormal vectors $\{e_1,\dotsc,e_n\}$ with the same span.

            innerproduct1[f_,g_]:=Sum[(f/.t->i)(g/.t->i), {i,1,4}]

                      innerproduct1[Subscript[u,j], Subscript[u,j]]*Subscript[u,j],  {j,1 ,i-1}];
               Subscript[u,i]/Sqrt[innerproduct1[Subscript[u,i].Subscript[u,i]]],{i, 1,k}];

Sorry if the program is wrong. I might be going ahead of what I read which I probably am.

I just learned somethings about the Gram-Schmidt process from reading an analysis text a couple days ago. I saw this question online and thought I would try to solve it with what I read. I came to some frustration and really wanted to know how to write a Mathematica program for this.

  • $\begingroup$ What is the issue with the program you wrote? $\endgroup$ Nov 4, 2013 at 20:14
  • $\begingroup$ I just fixed my program. I think this is what the question in bold is asking. Can someone please tell me if this is correct? Is there another way to do this? $\endgroup$
    – 9599
    Nov 4, 2013 at 20:54
  • $\begingroup$ Did you check the Mathematica document about 'Orthogonalize' command. There you can specify method as Gram-Schmidt. If you check the "Applications" part you can also find a related example for linearly independent vectors, the result is a set orthonormal with the given inner product. $\endgroup$
    – s.s.o
    Nov 4, 2013 at 21:02
  • $\begingroup$ It looks almost correct though I won't say I tested in any great detail. One issue I can see is use of a dot in the last call made to innerproduct1. I suspect a comma was wanted there. $\endgroup$ Nov 4, 2013 at 21:15
  • $\begingroup$ @DanielLichtblau Is it ok if you can show me your written program. I tried this for a couple days now and would like to compare this to someone who knows this. $\endgroup$
    – 9599
    Nov 4, 2013 at 22:26

1 Answer 1


There is a built-in command for orthogonalizing vectors by generating a Gram-Schmidt basis (as suggested by s.s.o in a comment). Say you have some linearly independent vectors (generated here using RandomReal). For example, this generates three 10-D vectors at random.

z = RandomReal[{-1, 1}, {3, 10}]

orthoZ = Orthogonalize[z]

gives the three vectors in orthonormal form, as you can check:

orthoZ.Transpose[orthoZ] // Chop
{{1., 0, 0}, {0, 1., 0}, {0, 0, 1.}}

You can also specify your own inner product using the optional second argument of Orthogonalize. For example:

Orthogonalize[{1, x, x^2, x^3}, Integrate[Times[##], {x, -1, 1}] &]

uses $<x,y>=\int x(t) y(t) dt$ as the inner product and orthogonalizes the first few polynomials.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.