2021-03-06 15:54:10 +01:00
|
|
|
% Argorithm 4: Back Substitution (Alg. 3.1.2)
|
2021-03-13 13:42:56 +01:00
|
|
|
function b = Alg4_back_substitution(U,b)
|
2021-03-06 14:15:22 +01:00
|
|
|
|
|
|
|
[n, m] = size(U);
|
|
|
|
if n ~= m
|
|
|
|
error('Matrix is not squared!')
|
|
|
|
end
|
|
|
|
|
|
|
|
if length(b) ~= n
|
|
|
|
error('Vector b has wrong length!')
|
|
|
|
end
|
|
|
|
|
2021-03-06 15:54:10 +01:00
|
|
|
if det(U) == 0
|
|
|
|
error('Matrix is not nonsingular!')
|
2021-03-06 14:15:22 +01:00
|
|
|
end
|
|
|
|
|
2021-03-07 22:56:18 +01:00
|
|
|
% b(n, :) so that matrices are also accepted
|
|
|
|
|
|
|
|
b(n, :) = b(n, :)/U(n, n);
|
2021-03-06 15:54:10 +01:00
|
|
|
for i = n-1:-1:1
|
2021-03-07 22:56:18 +01:00
|
|
|
b(i, :) = (b(i, :) - U(i, i+1 : n)*b(i+1 : n, :))/U(i, i);
|
2021-03-06 14:15:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|