I am trying to solve the inverse of a matrix A, using the equation AX=I and LU factorization. My lufact function worked originally, but when using to compute the inverse, A and X both end up as identity matrices.

1 回表示 (過去 30 日間)
I am trying to solve the inverse of a matrix A, using the equation AX=I and LU factorization. My lufact function worked originally, but when using to compute the inverse, A and X both end up as identity matrices.
function [A, X] = lufact(I)
% LUFACT LU factorization
% Gaussian elimination
for j = 1:n-1
for i = j+1:n
A(i,j) = I(i,j) / I(j,j); % row multiplier
I(i,:) = I(i,:) - A(i,j)*I(j,:);
end
end
X = rand(n,n);
end
  2 件のコメント
darova
darova 2019 年 9 月 24 日
You don't check if your multipliear is inf (I(j,j) == 0) ?
Athul Prakash
Athul Prakash 2019 年 10 月 9 日
Not sure that I follow your approach..
You want to find X such that AX=I, but when you factorize I, won't it produce any 2 factors which multiply to I (instead of one of them being A and the other X)?
Also, please share the dimensions of your matrix A.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by