0% found this document useful (0 votes)
55 views8 pages

Gram-Schmidt Coding Assignment

This document describes using the Gram-Schmidt process to orthonormalize three vectors in MATLAB. It first provides background on the Gram-Schmidt process and how it orthonormalizes a set of vectors. It then gives an example of applying the process by hand and in MATLAB to three sample vectors. Code is included in an appendix to implement the Gram-Schmidt process as a MATLAB function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views8 pages

Gram-Schmidt Coding Assignment

This document describes using the Gram-Schmidt process to orthonormalize three vectors in MATLAB. It first provides background on the Gram-Schmidt process and how it orthonormalizes a set of vectors. It then gives an example of applying the process by hand and in MATLAB to three sample vectors. Code is included in an appendix to implement the Gram-Schmidt process as a MATLAB function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

AE 5000 - ADVANCED MATHEMATICS

Gram-Schmidt Coding Assignment

By

Alvian Iqbal Hanif Nasrullah 13614013

PROGRAM STUDI TEKNIK DIRGANTARA

FAKULTAS TEKNIK MESIN DAN DIRGANTARA

INSTITUT TEKNOLOGI BANDUNG


2017
Gram – Schmidt Theory
In advanced mathematics, the Gram–Schmidt process is a method for orthonormalising a set of vectors in
an inner product space, most commonly the Euclidean space Rn equipped with the standard inner product.
The Gram–Schmidt process takes a finite, linearly independent set S = {v1, ..., vk} for k ≤ n and
generates an orthogonal set S′ = {u1, ..., uk} that spans the same k-dimensional subspace of Rn as S.
The Gram-Schmidt Process
We create the code of orthonormalising three vectors using gram-schmidt process in matlab. The process
use projection operator from one vector to other vector to create the basis. Actually, the basis vector use
one vector to be a basical operation. The projection of two vector can be mathematically described by :

For a physical form, we can see the projection as follow

This operator projects the vector v orthogonally onto the line spanned by vector u. Then the 3 dimensions
projection process will work as follows:

The basic vector always be a unit vector to make this easy to be spanned by any value.
Example
Find the orthonormal basis for 3 dimensions vectors using gram-schmidt process by hand-calculation and
matlab program
V=IR3
1 6 3
v1 = 1 v2=4 v3= 6
1 5 4

Using Hand Calculation


We project the vector each other
1
u1 = v1 = 1
1
<𝑢1 .𝑣2>
u2 = v2 – Proj u1 (v2) = v2 – <𝑢1 .𝑢1> u1

6 1
15
=4 – 3
*1
5 1
1
= −1
0
u3 = v3 – Proj u1 (v3) – Proj u2 (v3)
3 1 1
18 (−3)
= 6 – 3
*1 – 2
* −1
4 1 0
−3/2
= −3/2
3
Then, make it unit vector
1 0.5774
𝑒1 1
e1 = ‖𝑒1‖ = * 1 = 0.5774
√3
1 0.5774
−1 −0.4082
𝑒2 1
e2 = ‖𝑒2‖ = * −1 = −0.4082
√6
2 0.8165
1 0.7071
𝑒3 1
e3 = ‖𝑒3‖ = * −1 = −0.7071
√2
0 0
We check the basis vector is orthonormal each other by multiplying dot product of two vector, and we get
zero for the result. Multipliplying by dot product produce the value of e1.e2 = e1.e3 = e2.e3 = 0. So the
basis is orthonormal.

Using Matlab program


First, we make the source code of matlab to compute the solution. Source code appear on appendix. Make
sure the mfile code as a function which name is ‘gramschmidt.m’ . To calculate, input the initial variable
of the vectors that will be orthonormalized. We input the initial vector on Command Window as follow :

>> v1=[1;1;1];
>> v2=[6;4;5];
>> v3=[3;6;4];
>> [e1,e2,e3]=gramschmidt(v1,v2,v3)

After input the initial vector, the orthonormal unit basis vector will appear on Command Window.

e1 =
0.5774
0.5774
0.5774
e2 =
0.7071
-0.7071
0
e3 =
0.4082
0.4082
-0.8165
And we can get the visual figure of initial and basis vector on one space coordinate as follow

The basis vector can be different each operation depend on which vector orthonormalized first and the
sequence of vector projection. But all the basis vector must be orthogonal each other. To make sure, we
can multiple two basis vector by dot product. If the result of multiplication is zero, so the basis vector is
orthogonal each other and the process is true.
From the result, e1.e2 = e2.e3 = e1.e3 = 0
So, the basis must be orthogonal.
APPENDIX
MATLAB SOURCE CODE

function[y1,y2,y3]=gramschmidt(a,b,c)
matrix=[a';b';c'];
r=rank(matrix);
l=length(matrix);

if r ~=l
error('coba lagi, matrix tidak linearly independent')

end
v1=a;
v2=b-(dot(a,b)/(dot(v1,v1)))*a;
v3=c-(dot(a,c)/dot(v1,v1)*a)-(dot(c,v2)/dot(v2,v2)*v2);

y1=v1/sqrt(dot(v1,v1));
y2=v2/sqrt(dot(v2,v2));
y3=v3/sqrt(dot(v3,v3));

starts=zeros(3,3);
ends=[y1';y2';y3'];

quiver3(starts(:,1),starts(:,2),starts(:,3),ends(:,1),ends(:,2),ends(:,3),'linewidth',1.5)
hold on, grid on

akhir=[a';b';c'];
quiver3(starts(:,1),starts(:,2),starts(:,3),akhir(:,1),akhir(:,2),akhir(:,3))

xlabel('sumbu-x')
ylabel('sumbu-y')
zlabel('sumbu-z')
title('Gram Schmidt Process')
legend('basis gramschmidt','vektor awal')
grid minor

%process on Command Window


%[y11,y22,y33]=gramschmidt(a,b,c)
FLOWCHART

START

Input initial vectors

NO

Rank = length matrix?

YES

Process to get the basis

Plot 3D basis and initial vector

END
REFERENCE

https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process , accessed on September 7th ,


2017 at 02:30 PM
https://www.khanacademy.org/math/linear-algebra/alternate-bases/orthonormal-basis/v/linear-
algebra-the-gram-schmidt-process, accessed on September 7th , 2017 at 03:10 PM
https://www.khanacademy.org/math/linear-algebra/alternate-bases/orthonormal-basis/v/linear-
algebra-gram-schmidt-process-example, accessed on September 7th , 2017 at 03:15 PM
https://www.youtube.com/watch?v=Zk_ua7zBELg,accessed on September 7th, 2017 at 03:30 PM

You might also like