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 Ansicht (letzte 30 Tage)
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 Kommentare
Athul Prakash
Athul Prakash am 9 Okt. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by