Gram-Schmidt Process

How to use GS Process  figure  Update 2009-02-18
Please use MSIE browser to read this page.
This file is programmed with MSIE 6.0
Main engine: XYGraph v2.3 - web page graph   ☜☞   donate
The Cauchy-Schwarz Master Class   J. Michael Steele   ★★★★★
This file is personal home work. Output
may contain error. Please verify first.






<a name=bgn01>

Please fill in space dimension, it determine input box arrangement.
Space dimension 2 to 102   Sample data
Dimension 102 is very time-consuming, Suggest test just once.

If input 3D space vectors, need 3 vectors, each has three components.
R0000 and R0001 and R0002 are zeroth vector R00 three components.
R0100 and R0101 and R0102 are first vector R01 three components.
Other vector are similarly defined. To simplify work, use computer
sequence, start from zeroth, not start from first.
Please fill in data to following boxes. Output to box 2.


sample:jump sequential
[update] button read from Box 1. fill number to vector boxes above.
Box 1, verify input data

Box 2,Output result Sample data

Box 3, debug output Debug


<a name=980209a01>
2009-02-09-15-30 begin (9802151725trans.)
See figure for easier understanding.
Gram-Schmidt Process is widely used in math
physics and engineering. Its function is to
convert user-defined and not-very-accurate
input data. That is input vectors are not
exact perpendicular to each other and not
be exact length one. Gram-Schmidt Process 
convert user-input vectors to a set of 
orthonormal axis set. This set has both
orthogonal property and length-one property.
Common application is for 3D space axis.
Need three linearly independent vectors to
span a 3D space. Linearly independent vectors
means three vectors no two colinear and not
all coplane.

<a name="980209a02">
We require orthogonal property, because
projection procedure use perpendicular line
and parallel line to carry out calculation.

<a name="980209a03">
We require output set vectors all be length 
one. Because in rotation calculation, length
one and length two and length ten get same
treatment. Result is linear. For a general
length problem (length not one) We can solve
for length-one rotation, then multiply the
length to final length-one answer , get
length-general answer.
[[this property means linear.
f(x)=x*x is non-linear, because
f(2)=2*2=4
f(6)=6*6=36
inputA  2 *3 get inputB 6
outputA 4 *3 NOT get outputB 36
]]
2009-02-15-17-43 stop  translation
2009-02-15-19-05 start translation


For ground coordinate system, it is very 
easy to assign three mutual perpendicular
and length-one axis [1,0,0] and [0,1,0] 
and [0,0,1]
These vectors are orthonormal vectors.

<a name="980209a04">
Vector [a,b,c] length-one require that
sqrt(a*a+b*b+c*c)=1
Vector [1,0,0] length-one require that
sqrt(1*1+0*0+0*0)=1  which is correct and
easy.

Vector [a,b,c], [d,e,f] mutual perpendicular
require that
a*d+b*e+c*f = 0
Vector [1,0,0], [0,1,0] mutual perpendicular
require that
1*0+0*1+0*0 = 0  which is correct and easy.

<a name="980209a05">
But after rotation, deviate from above base
vectors. It is hard to determine rotated
mutual perpendicular and length-one vectors.

For example, space curve projector page
http://freeman2.com/curve3d2.htm
After assign eye coordinate to be (for example)
[1,2,-1], still need to assign second vector
point to screen-up direction. Second vector
must be perpendicular to first vector. How to
determine screen-up direction? It is easy to
give a rough direction. For example
<a name="980209a06">
[4,5,6] But [1,2,-1] and [4,5,6] are not
perpendicular to each other. Space curve
projector curve3d2.htm can not use [1,2,-1] 
and [4,5,6] directly. Because
eye coordinate is no longer [1,0,0] Now it 
is [1,2,-1]
Screen-up direction is no longer [0,0,1] 
Now it is [4,5,6].
Whole coordinate system rotated. In order 
to build rotation matrix, we need assign
[1,2,-1] and [4,5,6] and third vector, for
example [7,8,5]. These three vectors are
human-brain assigned values. If make three
all become length-one, that is easier job.
But how to make them perpendicular to each
other? This is a headache problem.
2009-02-09-16-10 doc. here
2009-02-15-19-25 trans. here

<a name="980209a07">
How to carry out vector length-one process?
Now use [1,2,-1] as example.
vector [a,b,c] length is sqrt(a*a+b*b+c*c)
vector [1,2,-1] length is 
L=sqrt(1*1+2*2+(-1)*(-1))
length is 2.449489742783178
Original vector [1,2,-1] divide by L=2.449...
get [1/L, 2/L, -1/L] . If do length check 
for new vector [1/L, 2/L, -1/L] its length
is one. This process is length-one procedure.
Other vector length-one process is the same.
2009-02-09-16-20 here

<a name="980209a08">
Above is length-one procedure.
How to make several vectors perpendicular to
each other? perpendicular need two vectors
compare with each other.
Now use [1,2,-1] and [4,5,6] two vectors to
illustrate orthogonal process.
Name [1,2,-1] as vector1, name [4,5,6] as
vector2.
vector1 is start up vector, it can do length
-one process, can not do orthogonal process.
Because second vector do not enter stage yet.

<a name="980209a09">
vector1 [1,2,-1] length-one process is
 [1/L, 2/L, -1/L] where L=2.449489742783178
vector1 [1,2,-1] length-one process result is
[0.4082482904638631, 0.8164965809277261,
-0.4082482904638631]
Above vector1 use simple note as [v11,v12,v13].

<a name="980209a10">
After vector1 [1,2,-1] is done,
vector2 [4,5,6] enter stage.
vector2 orthogonal process is relative to 
vector1.
vector2 orthogonal process and vector2 length
-one process has order. Do orthogonal process
first, then do length-one process.

<a name="980209a11">
Another word for orthogonal process is
from vector2 delete its component in vector1.
Because from vector2 delete its component in
vector1, vector2 has no component in vector1
two dot result is zero. Two vector's dot 
product equal to zero, that is perpendicular.
2009-02-09-16-46 Stop
2009-02-15-19-48 translation here

<a name="980213a01">
2009-02-13-11-33 start
2008-11-03-20-15 click [buy book] button
2008-11-06-13-11 receive inequality book
The Cauchy-Schwarz Master Class
J. Michael Steele
University of Pennsylvania
ISBN 978-0-521-54677-5
<a name="980213a02">
page 70 equation 4.28 is the base of this
file Gram-Schmidt Process
http://freeman2.com/gramsch2.htm

page 70 equation 4.28 is next
zk = xk - SUM[j=1,k-1](xk,ej)ej ---(a01)
and ek = zk/abs(zk)   ---(a02)
To read equation is relative headache,
see figure is easier.

Below use 2D and 3D problem as example.
2009-02-13-11-53 here

<a name="980213a03">
2D example vector is
vector0  x0=[1,2]
vector1  x1=[3,4]

equation become
z0=x0=[1,2]
e0=[1,2]/sqrt(1*1+2*2)  do length-one process
e0=[1,2]/2.23606797749979
e0=[0.4472, 0.8944]  this is answer.

<a name="980213a04">
Above is vector0 carry out length-one process.
Can not do orthogonal process. Because vector0
has no previous vector.

Below is vector1 need to do orthogonal process
and length-one process. vector1 has a previous
vector0.

<a name="980213a05">
x1=[3,4]
z1=[3,4]-([3,4] dot e0)e0 //delete component in vector0
z1=[3,4]-([3,4] dot [0.4472, 0.8944])e0
z1=[3,4]-(3*0.4472+4*0.8944)e0  //this e0 easy to forget
z1=[3,4]-(4.9192)e0 //(value) is vector dot result, non-vector
z1=[3,4]-(4.9192)[0.4472, 0.8944]  but e0 is vector
z1=[3-4.9192*0.4472,4-4.9192*0.8944]
z1=[0.80013376,-0.39973248] 
<a name="980213a06">
 z1 deleted component in vector0, but 
z1 length is not one. Below e1 is normalized z1. 
e1 length is one.
e1=[0.80013376,-0.39973248]/  
sqrt(0.80013376*0.80013376+(-0.39973248)*(-0.39973248))
  //above two lines are one equation.
e1=[0.80013376,-0.39973248]/0.894427
e1=[0.80013376/0.894427,-0.39973248/0.894427]
e1=[0.89457,-0.446914]  //this is answer.
Above hand calculation result
Below computer calculation result
e1=[0.8944271909999162,-0.4472135954999574]

<a name="980213a07">
Easy mistake step is
-([3,4] dot e0)e0  possibly mistake to
-([3,4] dot e0)

Above is 2D problem
<a name="980213a08">
Below is 3D problem
2009-02-13-12-17 here

Next is zeroth input vector
x0=[1,2,-1]
Below is 1st input vector
x1=[4,5,6]
Below is 2nd input vector
x2=[7,8,5]

<a name="980213a09">
zeroth input vector need only length-one
process.
z0=x0=[1,2,-1]
e0=[1,2,-1]/sqrt(1*1+2*2+(-1)*(-1)) length-one process.
e0=[1,2,-1]/2.449489742783178
e0=[0.408248, 0.816496, -0.408248]  this is answer

2009-02-15-20-14 stop  translation 
2009-02-16-09-30 start translation 

<a name="980213a10">
1st input vector
x1=[4,5,6]

z1=[4,5,6]-([4,5,6] dot e0)e0 //subtract vector0 from vector1
=[4,5,6]-([4,5,6] dot [0.408248,0.816496,-0.408248])e0
=[4,5,6]-(4*0.408248+5*0.816496+6*(-0.408248))e0
=[4,5,6]-3.265984*e0 //1st input vector has one previous vector
=[4,5,6]-3.265984*[0.408248, 0.816496, -0.408248]
=[4-3.265984*0.408248,
  5-3.265984*0.816496,
  6-3.265984*(-0.408248)
   ]
=[2.666668563968,
  2.333337127936,
  7.333331436032
  ]
z1 is the result of subtract vector0 from vector1
z1 length is not one.

<a name="980213a11">
Below do length-one process for z1, result is e1

e1=[2.666668563968,
    2.333337127936,
    7.333331436032
   ]/    //this line has a division sign
         //below sqrt() is length of z1 vector
sqrt(2.666668563968*2.666668563968
 +2.333337127936*2.333337127936
 +7.333331436032*7.333331436032
 )

<a name="980213a12">
e1=[2.666668563968,
    2.333337127936,
    7.333331436032
   ]/8.144527815248404

e1=[2.666668563968/8.144527815248404,
    2.333337127936/8.144527815248404,
    7.333331436032/8.144527815248404
   ]

<a name="980213a13">
e1=[0.3274182036280231,
    0.28649092817452015,
    0.9004000599770637
   ]  //this is answer.

<a name="980213a14">
Still want to see e2 procedure?
 e2 = z2/abs(z2)
before find e2 , need find z2 first
z2 and e2 perpendicular to both e0 and e1
z2 length is not one, e2 length is one.
 z2 = x2 - SUM[j=1,k-1](xk,ej)ej
 z2 = x2 - (x2,e0)e0 - (x2,e1)e1

<a name="980213a15">
"(x2,e0)" in "x2 - (x2,e0)e0" is vector x2 
component along e0 direction. This is a pure
number, not a vector, represent projection
length.
 (x2,e0) is dpt product of two vectors.
 if  x2=[a,b,c]  e0=[d,e,f]
then (x2,e0) = a*d+b*e+c*f

Write code, add '(' and ')' to form
 (a)*(d)+(b)*(e)+(c)*(f)
Because if a=3, d=-2 
 3*-2  is error expression
 (3)*(-2) is right expression

<a name="980213a16">
(x2,e0)e0 means projection length (x2,e0) ride
on top of vector e0 .
Now (x2,e0)e0 is a vector.

x2 - (x2,e0)e0 represent vector x2 subtract
vector (x2,e0)e0 
Result vector is a vector perpendicular to e0 .

 z2 = x2 - (x2,e0)e0 - (x2,e1)e1
 is a vector perpendicular to both e0 and e1.

<a name="980213a17">
This example use x2=[7,8,5]

just done result e0 and e1 are
e0=[0.408248, 0.816496, -0.408248]

e1=[0.3274182036280231,
    0.28649092817452015,
    0.9004000599770637
   ] 
To find e2 , to find z2 leave as an exercise.
It is not difficult, just longer.

<a name="980213a18">
This example has computer output. In this page
look for "Sample data" click "0", then click
"Run GS Process". Output to box2 and verify.
Verify result has two section,
First each orthonormal vector must have length one.
Second each pair orthonormal vector must have dot
product zero.
2009-02-13-12-46 stop
2009-02-16-09-52 translation here

<a name="980213a19">
2009-02-13-12-57 start
Please pay attention
Several start up vectors , their sequence has
strong influence to answer. It is easy to
understand.
First (for human, or zeroth for computer) vector
do not change direction, just change length to one.
Because first vector no "previous vector" can not
subtract component.

<a name="980213a20">
Second and following vectors, their before-process
and after-process change direction. Because each
subtract component along previous vector. This
subtraction change direction.
2009-02-13-13-04 stop

<a name="980216a">
2009-02-16-16-10 start
Program use
Space dimension [  ] 2 to 102
Practical space dimension is 2 and 3.
Space dimension 102 is far far away
from practical space dimension.
Program take care two digit space
dimension up to 99. All input boxes
are aligned. Set upper limit to 102
allow user test what happen if space
dimension is three digit. Program
still run normal, but three digit
input boxes are not aligned properly.
Higher space dimension, longer CPU
time.
2009-02-16-16-15 stop

<a name="980218a">
2009-02-18-11-25 start
9802181125
Gram-Schmidt Process program 
http://freeman2.com/gramsch2.htm
is done on
2009-02-14.
2009-02-16 done English version
2009-02-18 done auto-fill-tool.

<a name="980218b">
If you use this program gramsch2.htm
in 3D problem, you need input three
vectors, each vector three elements.
Total 3*3=9 numbers.
For ten dimensional problem, need
10*10=100 numbers.
<a name="980218c">
For hundred dimensional problem, need
100*100=10000 numbers.
Input data increase fast. Some large
scale problem has many zeros. In this
case, you can click "All fill with 0"
button, then put non-zero element in
<a name="980218d">
box 1 with the following format
[10][12]=6.092
[0][2]=0.646
[16][15]=0.765
.....
then click "Update" button.

<a name="980218e">
Above is random order.
Below is sequential order.

If your input data is in hand and complete,
should you insert data into small box one
by one? No, this "Update" tool allow you
put all data into box 1, then click "Update"
button. Program fill data for you.
<a name="980218f">
sequential order example is next
0.6460
6.0924
7.8583
7.8677
1.7625
5.9290
8.7314
9.9435
0.7657

<a name="980218g">
"Update" is a handy tool.

Thank you for visiting Freeman's web site.
Freeman 2009-02-18-11-59
9802181146
<a name=graph01>
Please click button for graphic explanation. (9802091716)






JavaScript program list
http://freeman2.com/jsindex2.htm
Space curve projector
http://freeman2.com/curve3d2.htm
Point to line, foot of perpendicular
http://freeman2.com/eyefoot2.htm


Gram-Schmidt Process
gramsch2.htm
Start coding 2009-02-04-15-10 (9802041510)
First upload 2009-02-16

URL of this page (Gram-Schmidt Process)
http://freeman2.com/gramsch2.htm
Chinese version URL
http://freeman2.com/gramsch1.htm

Thank you for visiting Freeman's page.
Freeman
2009-02-14-09-41