MATLAB: How to get the upper triangular matrix in Gauss Elimination

gausstriangleupper

for i=1:N-1
for j=i+1:N
if A(i)==A(j)==0
disp('The matrix cannot be solved');
Aprime(j)=Aprime(j)*(-(Aprime(i,i)/Aprime(j,i));
bprime(j)=bprime(j)*(-(Aprime(i,i)/Aprime(j,i));
How do I multiply row j of A' and b'by -a'ii/a'ji (where ii and ji are the subscripts)
How do I add row i and row j of A' and b'?

Best Answer

To error if there is a zero on the diagonal I would use the following:
assert(all(diag(A)),'Diagonal Element in A is zero')
And to show it working:
A = [1 2;3 4]
assert(all(diag(A)),'Diagonal Element in A is zero')
A = [1 2;3 0]
assert(all(diag(A)),'Diagonal Element in A is zero')