How do I get the upper triangular matrix in Gauss Elimination?

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'?

2 Comments

function [x, Aprime, bprime] = Gauss(A, b)
Aprime= A;
bprime= b;
Aprimebprime=[A,b];
[M,N]=size(Ab);
if (det (A))==0
disp ('Cannot solve the matrix');
end
for i=1:N-1
for j=i+1:N
if Aprime(i)==Aprime(j)==0
disp('The matrix cannot be solved');
Aprimebprime(i,j:M)=Aprimebprime(i,j:M)-Aprimebprime(i,i)/Aprimebprime(j,i)*Aprimebprime(j,j:M);
Aprimebprime(i)=Aprimebprime(i)+Aprimebrime(j);
x=Aprimebprime(i);
end
end
end
Hello, I have written the coding for the above but it is not working out for some of the matrices. 1. A= [0 1 3 2;2 1 4 0;1 1 2 1;1 2 3 1]; b=[14;11;11;15] 2. A=[1 1;1 1]=b=[2;3]
If the diagonal elements are zero, it should display an error Kindly help me out with this.

Sign in to comment.

 Accepted 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')

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!