Question
i need explanation for each line and thank you
% Gauss-Jordan method [m, n]-size (a): for j-1:m-1 for z-2:m if a (j,1)0 end end for i-j+1:m end end for j-m:-1:2 for i*)-1:-
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%% Gauss-Jordan method
% this code creates a identity matrix of size m in the first m columns
[m,n] = size(a);
% m is the number of rows in matrix a
% n is the number of columns in matrix a
for j = 1:m-1 % looping from 1 to m-1
for z = 2:m % looping from 2 to m
if a(j,j) == 0
% checking wheter the diagonal element of the matrix a is zero or not
t = a(1,:);
% assiging all the elements of first row to t
a(1,:) = a(z,:);
% assinging the zth rows elements to the first row
a(z,:) = t;
% assinging the first row elements to the zth row
% this process is interchanging rows when the diagonal element is 0
end % end of if condition
end % end of inner for loop
for i = j+1:m % looping from j+1 to m
a(i,:) = a(i,:) - a(j,:)*(a(i,j)/a(j,j));
% updating the ith row elements by subtracting the jth row elemnts
% multiplied by the ith row, ith column element and divided by the
% jth row jth column element from the ith row
end % end of inner for loop
end % end of outer for loop
for j = m:-1:2 % looping from m to 2 in steps of -1
for i = j-1:-1:1 % looping from j-1 to 1 in steps of -1
a(i,:) = a(i,:) - a(j,:)*(a(i,j)/a(j,j));
% updating the ith row elements by subtracting the jth row elemnts
% multiplied by the ith row, ith column element and divided by the
% jth row jth column element from the ith row
end % end of inner for loop
end % end of outer for loop


for s = 1:m % looping from 1 to m
a(s,:) = a(s,:)/a(s,s);
% updating the sth row of a by dividing the sth row by the sth row, sth
% column element
x(s) = a(s,n);
% assigning the sth row, last column of the a matrix to the sth element of
% x
end % end of for loop
disp('Gauss-Jordan method: ');
% command to display in the command window
a
% to display a matrix in the command window
x'
% to display transpose of the x vector in the command window
  

Add a comment
Know the answer?
Add Answer to:
i need explanation for each line and thank you % Gauss-Jordan method [m, n]-size (a): for j-1:m-1 for z-2:m if a (j,1)0 end end for i-j+1:m end end for j-m:-1:2 for i*)-1:-1:1 end end for s=1:m x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT