-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgschmidt.m
26 lines (26 loc) · 835 Bytes
/
gschmidt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function y = gschmidt(x,v) %last updated 5/11/94
%GSCHMIDT The Gram-Schmidt process on the columns in matrix
% x. The orthonormal basis appears in the columns of y
% unless there is a second argument in which case y
% contains only an orthogonal basis. The second argument
% can have any value.
%
% Use in the form ==> y = gschmidt(x) <== or
% ==> y = gschmidt(x,v) <==
%
% By: David R. Hill, MATH Department, Temple University
% Philadelphia, Pa., 19122 Email: hill@math.temple.edu
%
[m,n]=size(x);
y=x(:,1);
for k = 2:n % orthogonlization process
z=0;
for j=1:k-1
p=y(:,j);
z=z+((p'*x(:,k))/(p'*p))*p;
end
y=[y x(:,k)-z];
end
if nargin == 1
for j=1:n, y(:,j) = y(:,j)/norm(y(:,j));end % normalizing
end