4

Hello guys I am writing program to compute determinant(this part i already did) and Inverse matrix with GEPP. Here problem arises since i have completely no idea how to inverse Matrix using GEPP, i know how to inverse using Gauss Elimination ([A|I]=>[I|B]). I have searched through internet but still no clue, could you please explain me?

Here is my matlab code (maybe someone will find it useful), as of now it solves AX=b and computes determinant:

function [det1,X ] = gauss_czesciowy( A, b )
%GEPP
perm=0;

n = length(b);
if n~=m 
error('vector has wrong size');
end
for j = 1:n
    p=j;
    % choice of main element
    for i = j:n
        if abs(A(i,j)) >= abs(A(p,j))
            p = i;
        end
    end
    if A(p,j) == 0
        error('Matrix A is singular');
    end
    %rows permutation
    t       = A(p,:);
    A(p,:)  = A(j,:);
    A(j,:) = t;
    t       = b(p);
    b(p)    = b(j);
    b(j)    = t;
    if~(p==i)
    perm=perm+1;
    end

    % reduction
    for i = j+1:n
        t       = (A(i,j)/A(j,j)); 
        A(i,:)  = A(i,:)-A(j,:)*t; 
        b(i)    = b(i)-b(j)*t; 
    end 
end
%determinant
mn=1;
for i=1:n
    mn=mn*A(i,i);
end
det1=mn*(-1)^perm;
% solution
X   = zeros(1,n); 
X(n) = b(n)/A(n,n); 

if (det1~=0)
for i = 1:n
    s = sum( A(i, (i+1):n) .* X((i+1):n) ); 
    X(i) = (b(i) - s) / A(i,i); 
end
end
end
4

1 に答える 1

3

部分ピボットを使用したガウス消去のアルゴリズムは次のとおりです。基本的に、通常どおりガウス消去法を実行しますが、各ステップで行を交換して、使用可能な最大値のピボットを選択します。

逆を取得するには、行の切り替え方法を追跡し、順列行列 Pを作成する必要があります。順列行列は、A 行列と同じサイズの恒等行列ですが、同じ行切り替えが実行されます。次に、次のようになります。

[A] --> GEPP --> [B] and [P]

[A]^(-1) = [B]*[P]

念のため、いくつかのマトリックスでこれを試してみます。

編集:これを経験的にテストするのではなく、理由を説明しましょう。基本的に、A の行を切り替えるときに行っているのは、順列行列 P を乗算することです。GE を開始する前にこれを行うと、同じ結果が得られます。次のようになります。

[P*A|I] --> GE --> [I|B] or
(P*A)^(-1) = B

逆演算の性質により、これは次のように書き直すことができます。

A^(-1) * P^(-1) = B

そして、両辺に右側の P を掛けると、次のようになります。

A^(-1) * P^(-1)*P = B*P
A^(-1) * I = B*P
A^(-1) = B*P
于 2013-06-09T17:10:30.930 に答える