You are on page 1of 6

Problem 2.

Write a program to input any number of vector in R n and return


the orthogonal basis and orthonormal basis of the subspace spanned by these
vectors. (Use Gram - Schmidt process)

2.1. Theory  
a. Orthogonal sets

Let V be a vector space with an inner product.

Definition: Non-zero vector v1, v2…, vk ∈ V form an orthogonal set if they are orthogonal to
each other: (vi, vj) = 0 for i j.
If, in addition, all vector are of unit norm ‖v 1‖=1, then v1, v2,…, vk  is called an orthonormal
set.
We knew that: All Orthogonal set is linearly independent.

b.  Orthogonal projection

Let V be an inner product space


⟨ x,v ⟩
Let , v ∈ V, v 0. Then p = v is the orthogonal projection of the vector onto the vector
⟨ v,v ⟩
v.
⟨ x, v 1 ⟩ ⟨ x, v 2 ⟩ ⟨ x, v n ⟩
If v1, v2, … , vn  is an orthogonal set of vector then p= v1+ v2 +…+ v is the
⟨ v1 , v1⟩ ⟨ v2 , v2⟩ ⟨ v n ,n ⟩ n
orthogonal projection of the vector x onto the subspace spanned by v1,…,vn.
c. The Gram-Schmidt orthogonalization process
Let v be a vector space with an inner product.
Suppose x1, x2,...,, xn is an orthogonal basic for V.
⟨ x, v 1 ⟩ ⟨ x, v 2 ⟩ ⟨ x, v n ⟩
Let   v1+ v2 +…+ v
⟨ v1 , v1⟩ ⟨ v2 , v2 ⟩ ⟨ vn , vn ⟩ n
v1=x1
⟨ x2 , v 1 ⟩
v2 = x2 - v ,
⟨ v 1 , v1 ⟩ 1

⟨ x2 , v 1 ⟩ ⟨ x3 , v 2 ⟩
v1= x1- v - v ,
⟨ v 1 , v1 ⟩ 1 ⟨ v2 , v 2 ⟩ 2
.........................................................................................................

⟨ xn , v1⟩ ⟨ x n , v n-1 ⟩
v n = x1 - v 1 -…- v
⟨ v1 , v1⟩ ⟨ v n-1 , v n-1 ⟩ n-1

Then v1, v2,...,vn.


2.2. Steps to find the basis
Step 1: Fill the input of vector in array V1. To be precise V1= {v1,v2,v3,…} is a basis of the
space R(n).
Step 2: Transposing the vectors and computing the orthogonal basis:
Step 3: Let u1 = v1;
⟨ v2 , u 1 ⟩ ⟨ v3 , u 1 ⟩ ⟨ v3 , u 2 ⟩
Step 4: Calculate u2= v 2 - u 1 , u3= v 3 - u - u
⟨ u1 , u1 ⟩ ⟨ u1 , u 1 ⟩ 1 ⟨ u2 , u 2 ⟩ 2
Step 5: Calculate un.
Step 6: Compute the orthonormal basis:
u1 u2
Step 7: E1= ; E2= ;…
‖u1‖ ‖u2‖

2.3. Matlab command


function U = K(v) %v is a basis in space R(n) including the
vectors input
v=[…] %input the vectors
V = transpose(v); %transposing the vectors
m = size(V,1);
n = size(V,2);
U=zeros(m,n);
U(:,1)=V(:,1);
U(:,1) = V(:,1)/sqrt(V(:,1)'*V(:,1)); %calculate the orthogonal
basis of column 1
disp('Orthogonal basis');
disp(V(:,1));
for i=2:n %Because u1 = v1, take i starting from 2 to k
s=V(:,i);
for j=1 :i-1
s=s-(dot(V(:,i),U(:,j))/dot(U(:,j),U(:,j)))*U(:,j);
%calculate the orthogonal basis
end
U(:,i)=s;
disp(U(:,i));
U(:,i) = U(:,i)/sqrt(U(:,i)'*U(:,i)); %calculate the
orthonormal basis
disp('Orthonormal basis')
end

2.4 Examples
1st example:
2nd example:
3rd example:
2.5. Conclusion
By studying this we draw out a conclusion that we can make a good use of Matlab to solve
linear algebra problems without spend to much time working on manual solutions and
reduce the risk of finding the result of complex matrices.

You might also like