Householder 方法的 Scilab QR 分解输出不正确

问题描述 投票:0回答:1

好吧,我通过 Householder 变换对方阵 A 进行 QR 分解,但算法似乎存在一些问题,因此结果总是错误的。

clear;
clc;
function [P,Q,R] = QR_decompose(A)
    n = size(A,1);
    for j = 1:n 
        sigma = 0;
        for i = j:n
             sigma = sigma + A(i,j)*A(i,j);//compute norm 
        end 
        if sigma == 0 then disp('Singular'); 
           return; 
        end
        s = -sign(A(j,j)); 
        alpha = 1/(s*sqrt(sigma)*A(j,j)-sigma);
        A(j,j) = A(j,j)- s*sqrt(sigma);  
        for k = (j+1):n 
            x = 0
            for i = j:n
                x = x + A(i,j)* A(i,k);
            end 
            x = alpha* x; 
            for i = j:n 
                A(i,k)=A(i,k)+A(i,j)*x;
            end 
        end
    end 
    R = A
    Q = A^-1
endfunction  
A = [116 80 98 113; 80 66 80 93; 98 80 98 114; 113 93 114 133];
[P,Q,R]=QR_decompose(A)
disp('The permutation matrix is',P)
disp('The upper triangular matrix is',R) 
disp('The orthogonal matrix is', Q)

输出 R 并不是我期望的三角矩阵,但尽管我付出了很多努力也无法修复它

感谢任何帮助。非常感谢。

scilab decomposition
1个回答
0
投票

首先请注意:

  • Scilab 中已经存在 QR 分解(帮助 qr)
  • 您可以使用norm(A,"fro") 计算矩阵的弗罗贝尼乌斯范数 你需要修改你的
© www.soinside.com 2019 - 2024. All rights reserved.