calculate nullspace of stochiometric matrix
1 view (last 30 days)
Show older comments
Hello,
i try to calculate the nullspace of a stochiometric matrix with the algorithms lu, qr and svd. Standard is the null-command of matlab. i've got an example from a colleague but i did not understand every step and he is not there, so i cannot ask him. i think the lu-algorithm is wrong. can anyone find a mistake or way to make it better?
case 'standard'
K = null(S.Stoich,'r');
[n,m] = size(K);
G = S.Stoich*K %check the result
case 'lu'
A = S.Stoich;
[m,n] = size(A);
[L,U,Pr,Pc] = lu(sparse(A));
U = full(U);
r = rank(U);
Ui = U(1:r,1:r);
%Ue = pinv(Ui)
Ue = Ui*U(1:r,:); % =>Reduced Echelon-Form
K = full(Pc*[ -Ue(:,r+1:n); eye(n-r) ]);
G = Pr*A*Pc*K %check the result
case 'qr'
A = S.Stoich;
[m,n] = size(A);
if rank(A)<m
[m,n] = size(A);
[Q,R,P] = qr(A);
r = rank(A); % ginge auch direkt aus QR-Zerlegung
Rb = R(1:r,1:r); % Basis-Anteil
Rn = R(1:r,r+1:n); % Null-Anteil
K = P*[ -inv(Rb)*Rn; eye(n-r) ];
%error('matrix must not be rank-deficient');
else
[Q,R] = qr(A');
K = Q(:,m+1:n);
end
G = A*K %check the result
case 'svd'
A = S.Stoich;
% single value decomposition
[m,n] = size(A);
[U,s,V] = svd(A);
% numerische Rangbestimmung (alternativ: r=rank(A)):
tol = max(m,n)*s(1,1)*eps;
r = 0;
for i=1:min(size(s))
if s(i,i) >= tol, r = r+1; end
end
K = V(:,r+1:n);
G = A*K %check the result
Thank you
0 Comments
Answers (0)
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!