Sunteți pe pagina 1din 5

Modified Gram-Schmidt Orthogonalization in Matlab Elliott C. Back http://elliottback.com/wp/modified-gram-schmidt-orthogonalization-in-...

Elliott C. Back: Internet & Technology


Home
23 Is Destiny
Archives
Disclosure & Legal Notice

Modified Gram-Schmidt Orthogonalization in


Matlab
Posted in Code, Matlab by Elliott Back on October 16th, 2004.

Related Results
5 Growth Stocks for 2012
Discover Your Best Opportunities For Safe Portfolio Growth.

Refinance Now at 2.99%


Fed cuts rate below 0.25%. Lock-in a low rate today - No SSN required
Chitika | Opt out?

Without any ado at all, I present Matlab 6.5 code to do Modified Gram-Schmidt Orthogonalization,
otherwise known as QR Factorization. You can use a QR factorization to compute a number of things, the
least of which is the least squares solution, which can be computed in the following manner:

1. Start with Ax ~= b, where A is mxn, m > n (overdetermined system)


2. Compute A = Q * [R O]^T^, where Q is an orthogonal mxn matrix and R is an nxn upper triangular
matrix
3. Multiply Q^T^ * b to find new right hand side [c1 ... cn]^T^
4. Use back-substitution to solve R * x = [c1 ... cn]^T^ for x

Great!! Now you can find your own best fit lines. Heres the QR factorization algorithm:

function [q, r] = QR(A)


[m, n] = size(A);

q = zeros(m, n);
r = zeros(n, n);

for k = 1:n
r(k,k) = norm(A(1:m, k));

if r(k,k) == 0
break;
end

q(1:m, k) = A(1:m, k) / r(k,k);

for j = k+1:n
r(k, j) = dot(q(1:m, k), A(1:m, j));
A(1:m, j) = A(1:m, j) r(k, j) * q(1:m, k);
end
end

1 of 5 27-12-2011 11:49
Modified Gram-Schmidt Orthogonalization in Matlab Elliott C. Back http://elliottback.com/wp/modified-gram-schmidt-orthogonalization-in-...

Related Results
5 Growth Stocks for 2012
Discover Your Best Opportunities For Safe Portfolio Growth.

Chitika | Opt out?

Like One person likes this. Be the first of your friends.

This entry was posted on Saturday, October 16th, 2004 at 5:50 pm and is tagged with nbsp
nbsp nbsp nbsp nbsp, squares solution, qr factorization, least squares, gram schmidt, 0
orthogonalization, back substitution, zeros, best fit, orthogonal, matlab, algorithm, norm, cn, tweets

matrix. You can follow any responses to this entry through the RSS 2.0 feed. You can leave tweet
a response, or trackback.

6 Responses to Modified Gram-Schmidt Orthogonalization in Matlab


1. Shmuel says:
10/13/2010 at 6:52 am

Hi, well it nice and it works,

Do I need to run this function several time on the last result in order to improve the result?

Shmuel

Reply
2. Elliott Back says:
1/21/2008 at 10:09 am

Yes, but it wont give anything useful to you; youll end up with output like an identity matrix.

Reply
3. shriks says:
1/21/2008 at 6:10 am

Can this Modified Gram-Schmidt Orthogonalization be applicable to linearly dependent vectors ?

Reply
touseef says:
10/20/2010 at 1:50 am

no dear
we can not aplly this method for linearly dependent vector .

Reply
4. Anonymous says:
7/3/2005 at 6:41 am

function Q = mgs(A)

n = size(A,2);

2 of 5 27-12-2011 11:49
Modified Gram-Schmidt Orthogonalization in Matlab Elliott C. Back http://elliottback.com/wp/modified-gram-schmidt-orthogonalization-in-...

Q = A;

for k = 1:n-1,
Q(:,k) = A(:,k) ./ norm(A(:,k));
A(:,k+1:n) = A(:,k+1:n) Q(:,k) * (Q(:,k) * A(:,k+1:n));
end;
Q(:,n) = A(:,n) ./ norm(A(:,n));

Reply
5. Nemo says:
5/9/2005 at 4:35 pm

??? Index exceeds matrix dimensions.

Reply

Leave a Reply
Name (req)

Mail(req)

Website

Powered by WP Hashcash

The Search

search site archives

3 of 5 27-12-2011 11:49
Modified Gram-Schmidt Orthogonalization in Matlab Elliott C. Back http://elliottback.com/wp/modified-gram-schmidt-orthogonalization-in-...

Related Results

5 Growth Stocks for


2012
Discover Your Best
Opportunities For Safe Portfolio
Growth.
www.insideinvestingdaily.com

Refinance Now at 2.99%

Fed cuts rate below 0.25%.


Lock-in a low rate today - No
SSN required
www.MortgagesBestRates.com

Have Bad Credit?

Need to get your credit


repaired? Let us show you how.
www.bestconsumerresearch.com

Chitika | Opt out?

Related Posts:

US States GIS Dataset

As promised, I've got the cleaned up US state boundary data, perfect for creating visualizations in Excel
or Matlab. It's a dataset of (x,y) points ...

American States GIS Dataset

Update: The dataset is finished, and very pretty. For a CS490 project I'm working on I need to colour a
map of the US by ...

You Came
The New From
ElliottBack.com

I'm doing some


orthonormalization, orthogonalize
cool things , method, program
for the new ,ElliottBack.com.
factorization, procedure, orthonormalize
One , orthogonalisation
of them involves ,
integrating a community
tagging solution, to which I've added or modified the ...

4 of 5 27-12-2011 11:49
Modified Gram-Schmidt Orthogonalization in Matlab Elliott C. Back http://elliottback.com/wp/modified-gram-schmidt-orthogonalization-in-...

orthogonalization, matlab, gramschmidt, function, gramm, matrix, modified, using, decomposition,


schmidt, pseudocode, gram-schmidt, classical, process, algorithm, gram, code
Results by WP From / Where

The Meta

Log in
Administrative
RSS
Comments RSS

Mastering MATLAB 7
Duane C.
Hanselman...
New $68.39
Best $33.99

Modeling Derivatives
Applications in...
Justin London
New $130.93
Best $79.49

Computer
Explorations in
Signals and...
John R. Buck, Mich...
New $34.33
Best $20.00

Introduction to
Engineering
Programm...
Mark Austin, David...
New $131.25
Best $2.55

Introduction to Matlab
7 for Enginee...
William J Palm III...
Best $3.68

Privacy Information

Elliott C. Back is Copyright 2011 Bug & Bird, LLC

XHTML
CSS
RSS
Comments

5 of 5 27-12-2011 11:49

S-ar putea să vă placă și