Is there any method to calculate the inverse of matrix which changed a few values?
Afficher commentaires plus anciens
I have a large sparse matrix A and have gotten its inverse matrix inv(A) . Then I need to change an element value to get a new matrix, A1. I am trying to get the inverse of A1. Is there any way to do it , rather than recalculate the inv(A1)? Could I get some benefits from A or inv(A)?
e.g. (not a sparse matrix)
A = magic(5);
invA = inv(A);
A1 = A;
A1(1,5) = 1;
invA1 = inv(A1);% is there any way to do this?
I know this may be a math problem. It seems impossible for me. I just would like to know other's viewpoints of it. Thank you.
Réponse acceptée
Plus de réponses (2)
Vladimir Sovkov
le 1 Août 2020
1 vote
I am not sure how much profitable it is numerically, but the Sherman Morrison theorem can be a way, see https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula
In your example, u vector there should be chosen with only the 1st nonzero element and v vector with only the 5th nonzero element so that u1*v5=(1-A15).
2 commentaires
Vladimir Sovkov
le 1 Août 2020
In your example, it turns to
(try to rederive it by yourself to ensure that I have not mistaken somewhere)
(try to rederive it by yourself to ensure that I have not mistaken somewhere)
wei zhang
le 2 Août 2020
Bruno Luong
le 1 Août 2020
Modifié(e) : Bruno Luong
le 1 Août 2020
Apply this Sherman Morisson's formula in the page provided by Vladimir, if one set a single change: A(i,j) to new value newAij, the update should goes like this
function [Amod, iAupdate] = updateinv(A, i, j, newAij, iA)
% INPUTS:
% A (n x n) matrix
% i, j, newAij are scalars: A(i,j) will change to newAij
% iA inverse of A
% OUTPUTS:
% Amod: n x n matrix subjected to this modification
% iAupdate: inverse of Amod, updated using Sherman–Morrison formula
Amod = A;
Amod(i,j) = newAij;
d = newAij-A(i,j);
c = 1+d*iA(j,i);
tol = max(size(A)) * eps(norm(A));
if abs(c) < tol
warning('update matrix might be inaccurate');
if c > 0
c = tol;
else
c = -tol;
end
end
iAupdate = iA - d/c * (iA(:,i)*iA(j,:));
end
Test script
% testupdate.m
% Random matrix test
A = rand(5);
iA = inv(A);
% Random change
i = randi(size(A,1));
j = randi(size(A,2));
newAij = 10;
% Update matrix and its inverse
[Amod, iAupdate] = updateinv(A, i, j, newAij, iA);
% Check
iAmod = inv(Amod)
iAupdate
relerr = norm(iAupdate-iAmod,'fro')/norm(iAmod,'fro')
Result:
>> testupdate
iAmod =
0.3427 -0.2397 0.0926 -0.1965 -0.0649
-3.1551 3.3784 0.1696 1.3277 -0.5608
-4.7509 1.9002 0.1144 2.6354 0.9978
5.2877 -3.8865 -0.3091 -2.5948 1.2505
-1.4484 1.5561 0.1196 1.7662 -1.5276
iAupdate =
0.3427 -0.2397 0.0926 -0.1965 -0.0649
-3.1551 3.3784 0.1696 1.3277 -0.5608
-4.7509 1.9002 0.1144 2.6354 0.9978
5.2877 -3.8865 -0.3091 -2.5948 1.2505
-1.4484 1.5561 0.1196 1.7662 -1.5276
relerr =
4.0984e-16
From my experience this formula is not terribly useful for 2 reasons
- I rarely store inverse of matrix, epsecially medium/large size.
- One can lost precision when apply this formula multiple times.
1 commentaire
wei zhang
le 2 Août 2020
Catégories
En savoir plus sur Partial Differential Equation Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

