0% found this document useful (0 votes)
92 views

Gram Schmidt

This document describes a Matlab function called gschmidt that performs the Gram-Schmidt orthogonalization process. The function takes a matrix V as input and outputs an upper triangular matrix R and unitary matrix Q such that A = Q*R. The document provides an example usage of the gschmidt function on a sample matrix s and verifies it produces the correct output.

Uploaded by

coolboy_usama
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Gram Schmidt

This document describes a Matlab function called gschmidt that performs the Gram-Schmidt orthogonalization process. The function takes a matrix V as input and outputs an upper triangular matrix R and unitary matrix Q such that A = Q*R. The document provides an example usage of the gschmidt function on a sample matrix s and verifies it produces the correct output.

Uploaded by

coolboy_usama
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

The Gram-Schmidt process in Matlab

Yingwei Wang

Department of Mathematics, Purdue University, West Lafayette, IN
Some students said that they could not nd the so call gschmidt function
in the Matlab in their computers. So I wrote this routine to achieve the Gram-
Schmidt orthogonalization process in Matlab.
function [Q,R]=gschmidt(V)
% Input: V is an m by n matrix of full rank m<=n
% Output: an m-by-n upper triangular matrix R
% and an m-by-m unitary matrix Q so that A = Q*R.
[m,n]=size(V);
R=zeros(n);
R(1,1)=norm(V(:,1));
Q(:,1)=V(:,1)/R(1,1);
for k=2:n
R(1:k-1,k)=Q(:,1:k-1)*V(:,k);
Q(:,k)=V(:,k)-Q(:,1:k-1)*R(1:k-1,k);
R(k,k)=norm(Q(:,k));
Q(:,k)=Q(:,k)/R(k,k);
end

E-mail address: [email protected]; Tel : 765 237 7149


I
Yingwei Wang MA 265 Linear Algebra
Take the Exercise 10.3 # 1 for example.
>> s = [1 1 1; 2 0 0; 0 0 1]
s =
1 1 1
2 0 0
0 0 1
>> [x y]=gschmidt(s)
x =
0.4472 0.8944 -0.0000
0.8944 -0.4472 0.0000
0 0 1.0000
y =
2.2361 0.4472 0.4472
0 0.8944 0.8944
0 0 1.0000
Note that it is an alternative to use routine QR in Matlab, which gives the
same results.
II

You might also like