diff --git a/Direct Methods for Solving Linear Systems/Alg11.m b/Direct Methods for Solving Linear Systems/Alg11.m new file mode 100644 index 0000000..3fd774b --- /dev/null +++ b/Direct Methods for Solving Linear Systems/Alg11.m @@ -0,0 +1,21 @@ +function [Q R] = Alg11(A) +% Algorithm 11: QR factorization via Housholder algorithm. + +[m, n] = size(A); + +if ~ (m>=n) + error("m has to be greater or equal n!") +end + +for j = 1:n + [v, beta] = householder(A(j:m, j)) + A(j:m, j:n) = (eye(m-j+1)-beta*(v*v.'))*A(j:m, j:n) + if j < m + A(j+1:m, j) = v(2:m-j+1) + end +end + +R = triu(A) + +end + diff --git a/Direct Methods for Solving Linear Systems/Alg13.m b/Direct Methods for Solving Linear Systems/Alg13.m new file mode 100644 index 0000000..1b647af --- /dev/null +++ b/Direct Methods for Solving Linear Systems/Alg13.m @@ -0,0 +1,6 @@ +function [Q R] = Alg13(A) + + + +end + diff --git a/Direct Methods for Solving Linear Systems/householder.m b/Direct Methods for Solving Linear Systems/householder.m new file mode 100644 index 0000000..36ea007 --- /dev/null +++ b/Direct Methods for Solving Linear Systems/householder.m @@ -0,0 +1,27 @@ +function [v,beta] = householder(x) +% householder takes vertical vector x + +if ~iscolumn(x) + x = x.'; +end + +n = length(x); +sig = x(2:n).' * x(2:n); +v = [1; + x(2:n)]; + + if isempty(sig) || (sig == 0) + beta = 0; + else + mu = sqrt(x(1)^2+sig); + if x(1) <= 0 + v(1) = x(1) - mu; + else + v(1) = -sig/(x(1) + mu); + end + beta = 2*v(1)^2/(sig + v(1)^2); + v = v/v(1); + end + +end +