I have a function:
function [A_new, b_new] = forward_elimination(A, b)
A_new = A;
b_new = b;
[n,n]=size(A);
if any(diag(A)==0)
error('cannot compute')
end
for row=1:n-1
for i=row+1:n
factor=A(i,row)/A(row,row);
for j=row:n
A(i,j)=A(i,j)-factor*A(row,j);
end
b(i)=b(i)-factor*b(row);
end
A_new=A;
b_new=b;
end
end
This function provides the correct answer, however, I want the diagonals to be one. For example, when inputting a matrix A=[1 2 3; 4 5 6; 7 8 8] and b=[1;2;3], so: [A_new,b_new]=forward_elimination(A,b)
I want to produce a simplified matrix.
In this example, A_new=[1 2 3; 0 1 2; 0 0 1] b_new=[1;2/3;0]
However, my current code produces A_new=[1 2 3; 0 -3 -6; 0 0 -1] and b_new=[1;-2;0]
How do I simplify the function even more?