Skip to content

Commit

Permalink
moved ld
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Feb 2, 2016
1 parent c103d3c commit 799d529
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
14 changes: 0 additions & 14 deletions chapter13/LDS/ld.m

This file was deleted.

18 changes: 0 additions & 18 deletions chapter13/LDS/ld_.m

This file was deleted.

33 changes: 33 additions & 0 deletions common/ld.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
% function [L, D] = ld(X)
% % LD factorization produces LDL'=X*X' which is the same as [L,D] = ldl(X*X');
% % the underlying algorithm is Gram-Schmidt orthogonalization
% [d,n] = size(X);
% m = min(d,n);
% L = eye(d,m);
% Q = zeros(m,n);
% D = zeros(m,1);
% for i = 1:m
% L(i,1:i-1) = X(i,:)*bsxfun(@times,Q(1:i-1,:),1./D(1:i-1))';
% Q(i,:) = X(i,:)-L(i,1:i-1)*Q(1:i-1,:);
% D(i) = dot(Q(i,:),Q(i,:));
% end
% L(m+1:d,:) = X(m+1:d,:)*bsxfun(@times,Q,1./D)';

function [L, D] = ld(X)
% LD factorization produces LDL'=X*X' which is the same as [L,D] = ldl(X*X');
% the underlying algorithm is modified Gram-Schmidt orthogonalization
[d,n] = size(X);
m = min(d,n);
L = eye(d,m);
Q = zeros(m,n);
D = zeros(m,1);
for i = 1:m
v = X(i,:);
for j = 1:i-1
L(i,j) = v*Q(j,:)'/D(j);
v = v-L(i,j)*Q(j,:);
end
Q(i,:) = v;
D(i) = dot(Q(i,:),Q(i,:));
end
L(m+1:d,:) = X(m+1:d,:)*bsxfun(@times,Q,1./D)';

0 comments on commit 799d529

Please sign in to comment.