• No results found

5.10 The Gram-Schmidt algorithm

N/A
N/A
Protected

Academic year: 2021

Share "5.10 The Gram-Schmidt algorithm"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

NE112 Linear algebra for nanotechnology engineering

Douglas Wilhelm Harder, LEL, M.Math.

[email protected] [email protected]

5.10 The Gram-Schmidt algorithm

Introduction

• In this topic, we will

– Learn about the best approximation of a given vector of collection of m mutually orthogonal vectors

Define the Gram-Schmidt algorithm for taking a set of m vectors and returning a collection of at most m mutually orthogonal unit vectors

– Look at examples as go through the steps

The Gram-Schmidt algorithm 1

(2)

Best approximations

Suppose we have two vectors u1and u2that are orthogonal – Neither contains information about the other

Recall the best approximation of a given vector v of either of this is found by calculating the projection:

3

1

( )

proju v proju2

( )

v

Best approximations

Question: what is the best approximation of v as a linear combination of two orthogonal vectors u1and u2?

– As before, minimizing is equivalent to minimizing

The Gram-Schmidt algorithm

4

1 1 2 2 2

 

− −

v u u

2

1 1 2 2 2 1 1 2 2, 1 1 2 2

     

− − = − − − −

v u u v u u v u u

1 1 2 2

2

1 1 1 1 1 1 2 1 2

2

2 2 1 2 2 1 2 2 2

, , ,

, , ,

, , ,

 

   

   

= − −

− + +

− + +

v v v u v u

u v u u u u

u v u u u u

2

1 1 1 1 1

2

2 2 2 2 2

,

2 , ,

2 , ,

 

 

=

− +

− +

v v

u v u u

u v u u

3

(3)

Best approximations

Thus, the best approximation of v as a linear combination of two orthogonal vectors is:

Thus, given m vectors u1, …, um, all of which are mutually orthogonal, then the best approximation of v as a linear combination of all these vectors is

5

( ) ( )

1 2

proju v +proju v

( ) ( ) ( )

1 2

proj proj proj

+ + + m

u v u v u v

Best approximations

• Next, consider the work required to calculate this best approximation:

• We could reduce the work by half if we normalized all of the vectors:

The Gram-Schmidt algorithm

1 2

1 2

1 1 2 2

,

, ,

, , ,

m

m

m m

+ + + u v

u v u v

u u u

u u u u u u

1 1 2 2

ˆ , ˆ + ˆ , ˆ + + ˆm, ˆm u v u u v u u v u 5

(4)

Gram-Schmidt algorithm

Problem:

Suppose we have m vectors u1, …, um, none of which are necessarily normalized and no two of which are

necessarily orthogonal

Can we convert these into an associated collection of at most m vectors, all of which are unit vectors, and all of which are mutually orthogonal?

7

Gram-Schmidt algorithm

Solution:

The Gram-Schmidt algorithm.

Step 1.

Normalize the first vector, so define

The Gram-Schmidt algorithm

8 1

1

1 2

ˆ  u

u u

7

(5)

Gram-Schmidt algorithm

Step 2.

Subtract from u2the projection of u2onto

If u2is now 0, it was a scalar multiple of ,

so it contains no additional information: discard it Otherwise, normalize the second vector, so define

9 22− ˆ1, 2 ˆ1

u u u u u

ˆu1

2 2

2 2

ˆ  u

u u

ˆu1

Example

• Suppose we have the two vectors and

• Step 1:

• Step 2:

The Gram-Schmidt algorithm

1

1.5 2.0

 

= − 

u 2 3.5

4.5

 

=  

 

u

2 2 1 2 1

3.5 0.6 3.5 0.6

ˆ , ˆ ,

4.5 0.8 4.5 0.8

       

 − = − −      −  u u u u u

( )

3.5 0.6

4.5 1.5 0.8

   

= − − − 

2 2

2 2

4.4 ˆ 3.3

5.5

 

 

 

u =

u u

0.6 0.8

 

= − 

1 1

1 2

1.5 ˆ 2.0

2.5

 

− 

 

u =

u u

4.4 3.3

 

=  

 

0.8 0.6

 

=  

 

9

(6)

Example

• Note that and are both unit vectors and are orthogonal to each other

• Note that we can easily reconstruct the original vectors as a linear combination of these two vectors, so no information was lost

Also, given any vector in R2, say , the best approximation is

In this case, the best approximation equals v

11 1

ˆ 0.6 0.8

 

= − 

u 2 0.8

ˆ 0.6

 

=  

 

u

7 20

 − 

= −  v

1 1 2 2

0.6 0.8 7

ˆ , ˆ ˆ , ˆ 11.8 17.6

0.8 0.6 20

     − 

+ = − −    = −  u v u u v u

Example

• Suppose we have the two vectors and

• Step 1:

• Step 2:

The Gram-Schmidt algorithm

12 1

1 1 1 1

 

− 

 

= 

− 

 

u 2

6 2 1 3

 

− 

 

=− 

− 

 

u

1 1

1

1 2

ˆ  u =u2

u u

22− ˆ1, 2 ˆ1

u u u u u

2 2

2

2 2

ˆ  u =u5

u u

3.5 0.5 3.5 0.5

 

 

 

=− 

− 

 

0.5 0.5 0.5 0.5

 

− 

 

= 

− 

 

6 0.5

2 0.5

1 5 0.5

3 0.5

   

−  − 

   

= −

−   

−  − 

   

0.7 0.1 0.7 0.1

 

 

 

=− 

− 

 

11

(7)

Example

• Thus, we have and

• The best approximation of is found by calculating

13 1

0.5 ˆ 0.5

0.5 0.5

 

− 

 

= 

− 

 

u 2

0.7 ˆ 0.1

0.7 0.1

 

 

 

=− 

− 

 

u

1 1 2 2

0.5 0.7

0.5 0.1

ˆ , ˆ ˆ , ˆ 6.5 11.3

0.5 0.7

0.5 0.1

   

−   

   

+ = −

  − 

−  − 

   

u v u u v u

5 4 11 3

− 

− 

 

= 

− 

 

v

4.66 4.38 11.16 2.12

− 

− 

 

= 

− 

 

Gram-Schmidt algorithm

Step 3.

Subtract from u3the projection of u3onto If u3is now 0, it was a scalar multiple of ,

so it contains no additional information: discard it Subtract from this new u3the projection of u3onto

If u3is now 0, it was a linear combination of and , so it contains no additional information: discard it Otherwise, normalize the this new third vector, so define

The Gram-Schmidt algorithm

33− ˆ1, 3 ˆ1

u u u u u

ˆu1

3 3

3 2

ˆ  u

u u

ˆu1

33− ˆ2, 3 ˆ2

u u u u u

ˆu2

ˆu1

ˆu2

13

(8)

Example

• Suppose we now have , and

• We have and ,

and thus we need only apply Gram-Schmidt to u3

15 1

1 1 1 1

 

− 

 

= 

− 

 

u 2

6 2 1 3

 

− 

 

=− 

− 

 

u

1

0.5 ˆ 0.5

0.5 0.5

 

− 

 

= 

− 

 

u 2

0.7 ˆ 0.1

0.7 0.1

 

 

 

=− 

− 

 

u

3

2 3 12 1

 

 

 

=− 

 

 

u

Example

• Step 3:

The Gram-Schmidt algorithm

16 33− ˆ1, 3 ˆ1

u u u u u

5.5 0.5 8.5 2.5

 

− 

 

=− 

− 

 

( )

2 0.5

3 0.5

12 7 0.5

1 0.5

   

  − 

   

= − −

−   

  − 

   

33− ˆ2, 3 ˆ2

u u u u u

1.5 1.5 1.5 1.5

− 

− 

 

=− 

− 

 

5.5 0.7

0.5 0.1

8.5 10 0.7

2.5 0.1

   

−   

   

= −

−  − 

−  − 

   

3 3

3

3 2

ˆ  u =u3

u u

0.5 0.5 0.5 0.5

− 

− 

 

=− 

− 

 

15

(9)

Example

• Thus, we have , and

• The best approximation of is found by calculating

17 1

0.5 ˆ 0.5

0.5 0.5

 

− 

 

= 

− 

 

u 2

0.7 ˆ 0.1

0.7 0.1

 

 

 

=− 

− 

 

u

1 1 2 2 3 3

ˆ , ˆ + ˆ , ˆ + ˆ , ˆ u v u u v u u v u

5 4 11 3

− 

− 

 

= 

− 

 

v

4.91 4.63 10.91 2.37

− 

− 

 

= 

− 

 

3

0.5 ˆ 0.5

0.5 0.5

− 

− 

 

=− 

− 

 

u

0.5 0.7 0.5

0.5 0.1 0.5

6.5 11.3 0.5

0.5 0.7 0.5

0.5 0.1 0.5

    − 

−    − 

     

= − +

  −  − 

−  −  − 

     

Gram-Schmidt algorithm

Step k.

Subtract from ukthe projection of ukonto

for ℓ = 1, 2, …, k – 1 where we did not discard that vector

If at any point, uk= 0, we discard this vector.

Otherwise, normalize the this new vector, so define

The Gram-Schmidt algorithm

1 1

ˆ , ˆ

kkk

u u u u u

ˆu

2

ˆk k

k

u

u u

2 2

ˆ , ˆ

kkk

u u u u u

1 1

ˆ , ˆ

kkk k k

u u u u u

17

(10)

Gram-Schmidt algorithm

• To summarize:

Given m vectors u1through um, to convert these into a collection of mutually orthogonal unit vectors:

Starting with u1, normalize it and assign that to

Then, letting k = 2, 3, 4, …, m, do the following:

Subtract from ukthe projection of it onto

Repeat this, subtracting form ukthe projection of it onto each that was not discarded where ℓ = 2, …, k – 1

If at the end of this process, uk= 0, then discard this vector

Otherwise, normalize ukand assign it to

19

ˆu1

ˆu1

ˆu

ˆk u

Gram-Schmidt algorithm

• Warning: There are two forms of this algorithm

– The most common one taught is not numerically stable

That means, it works great for toy examples taught at the undergraduate level, but it fails when the vectors are numeric – The algorithm taught in this class is more stable numerically

You will cover numerical stability in your course on numerical analysis and methods

The Gram-Schmidt algorithm

20

19

(11)

Summary

• Following this topic, you now

– Know that you can easily calculate the best approximation of a given vector as a linear combination of mutually orthogonal vectors

– Understand that the Gram-Schmidt algorithm can take a collection of arbitrary vectors and convert them into a collection of mutually orthogonal unit vectors

21

References

[1] https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process [2] https://en.wikipedia.org/wiki/Inner_product_space

The Gram-Schmidt algorithm 21

(12)

Acknowledgments

None so far.

23

Colophon

These slides were prepared using the Cambria typeface. Mathematical equations use Times New Roman, and source code is presented using Consolas.

Mathematical equations are prepared in MathType by Design Science, Inc.

Examples may be formulated and checked using Maple by Maplesoft, Inc.

The photographs of flowers and a monarch butter appearing on the title slide and accenting the top of each other slide were taken at the Royal Botanical Gardens in October of 2017 by Douglas Wilhelm Harder. Please see

https://www.rbg.ca/

for more information.

The Gram-Schmidt algorithm

24

23

(13)

Disclaimer

These slides are provided for the NE 112 Linear algebra for nanotechnology engineering course taught at the University of Waterloo. The material in it reflects the authors’ best judgment in light of the information available to them at the time of preparation.

Any reliance on these course slides by any party for any other purpose are the responsibility of such parties. The authors accept no responsibility for damages, if any, suffered by any party as a result of decisions made or actions based on these course slides for any other purpose than that for which it was intended.

25

25

References

Related documents

Methods: A systematic literature review was conducted to identify case-control (CC) and cohort studies that examined the association between mesothelioma and non-occupational

The discrepancies may be because the previous survey by the Ministry of health Malaysia included data from both hospital and health clinics while the data in the current

Our main finding was that for all brain regions examined in the acute phase of brain injury, the connectivity pro files for a multitude of large-scale resting-state networks were found

Relevant to the welcoming nature of the Germany policy is that the residence permit is granted for three years and if the entrepreneur sustains him- or herself during these three

onal basis of V with the given inner product and use the expansion theorem to express v as a linear combination of the basis vectorsb. In each case, use the Gram-Schmidt algorithm

It has been accepted for inclusion in Provenance, Journal of the Society of Georgia Archivists by an authorized editor of DigitalCommons@Kennesaw State University.. For

There are five studies that have assessed treatment response in direct comparisons of medication with combined medication- psychological treatments in social phobia (two SSRI

The number of iterations is denoted It., the computation time (in seconds) for construction of the preconditioner is t prec , the com- putation time (in seconds) for the resolution is