% Mat-1.3379 Dynaamisten systeemien erikoiskurssi Eirola/Hannukainen
%
% compute the right inverse of AI with LU-dec.
%
% 


function AIx = luifun(A,x)


[L,U,P]=lu(A);

[n,m] = size(A);

% NOTE : in realworld computing the inverse is a bad idea.
%        only opearation to vector i.e. AI*x wich can be done
%        without explicitely construction the inverse.

U1 = U(1:n,1:n);

AIx = [(P*L*U1)\x; zeros(m-n,1)];

