-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbksub.m
28 lines (26 loc) · 901 Bytes
/
bksub.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function y = bksub(A,b) %last updated 2/17/98
%BKSUB Perform back substitution on upper triangular
% system Ax = b. If A is not square, upper
% triangular and nonsingular an error message is
% displayed. In case of an error the solution returned is
% as an empty matrix.
%
% Use in the form ---> bksub(A,b) <---
%
%By: David R. Hill, MATH. Dept. , Temple University,
% Philadelphia, Pa. 19122
% Email: [email protected]
if (size(A)==size(A') & all(all(A==triu(A))) & abs(prod(diag(A))) > eps)
n=length(b);
x=zeros(n,1);
for j=n:-1:1
x(j)=(b(j)-A(j,:)*x)/A(j,j);
end
y=x;
else
disp('Error in function bksub.')
disp('Coefficient matrix not square,')
disp('not upper triangular, or has a zero pivot.')
y=[];
return
end