程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Householder Reduction Matlab Version

Householder Reduction Matlab Version

編輯:C++入門知識

Householder Reduction Matlab Version


function [T, P] = householder(A)
% Formations: RA = T, where A is original matrix
% The implementation of Householder Reduction
% R is constructed as a product of elementary reflector
% T is upper triangular matrix

% Author: Zhenlin Du(Johnsondu)
% Email:  [email protected]
% Time:   2014-11-28 14:00

A = double(A)
[m, n] = size(A); % m- number of rows, n- number of columns

iter = 0;
if m > n
    iter = n;
else
    iter = m - 1;
end

T = A;
P = eye(m);

for i = 1 : iter
    % take the first column
    u = T(i:m, i);
    % construct identity matrix
    I = eye(m-i+1);
    e1 = I (:, 1);
    % u is elementary relector.
    u = u - norm(u) * e1;
    R11 = eye(m-i+1) - 2 * (u * u') / (u' * u);
    R1 = eye(m);
    for j = i: m
        R1(j, i: m) = R11(j-i+1, :);
    end
    T = R1 * T;
    P = R1 * P;
end


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved