Skip to content

Instantly share code, notes, and snippets.

@gramian
Last active July 18, 2016 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gramian/66fdf1a68ca51893d81f2c1da4a4ff4f to your computer and use it in GitHub Desktop.
Save gramian/66fdf1a68ca51893d81f2c1da4a4ff4f to your computer and use it in GitHub Desktop.
Approximate matrix inverse of quadratic complexity ( A⁻¹ ≈ D⁻¹ - D⁻¹ E D⁻¹ )
function x = ainv(m)
% ainv - approximate inverse
% by Christian Himpe 2016
% released under BSD 2-Clause License ( opensource.org/licenses/BSD-2-Clause )
d = diag(m);
d(d~=0) = 1.0./d(d~=0);
n = numel(d);
x = bsxfun(@times,m,-d);
x = bsxfun(@times,x,d');
x(1:n+1:end) = d;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment