Академический Документы
Профессиональный Документы
Культура Документы
RATING
ALGORITHM FLOWCHART
1. Start
2. Read the order of the matrix ‘n’
and read the coefficients of the
linear equations.
3. Do for k=1 to n
Do for l=k+1 to n+1
a[k][l] = a[k][l] / a[k][k]
End for l
Set a[k][k] = 1
Do for i=1 to n
if (i not equal to k) then,
Do for j=k+1 to n+1
a[i][j] = a[i][j] – (a[k][j] * a[i][k])
End for j
End for i
End for k
4. Do for m=1 to n
x[m] = a[m][n+1]
Display x[m]
End for m
5. Stop
ENGLISH MATLAB PROGRAM
function [x,err]= gauss_jordan_elim(A,b)
1. Write the augmented matrix of the A = [1 1 1;2 3 5; 4 0 5] % input for augmented matrix A
b = [5 ; 8; 2] % intput for matrix B
system. [n,m]=size(A); % finding the size of matrix A
2. Use row operations to transform the err =0; % calculation of error
augmented matrix in the form described x=zeros(n,1); % calling fuction zero
if n ~= m
below, which is called the reduced row disp('error: n~=m'); % displaying error if found
echelon form (RREF). (a) The rows (if err = 1;
any) consisting entirely of zeros are end % end of the scope of if
if length(b) ~= n % finding the legth of matrix B
grouped together at the bottom of the disp('error: wrong size of b'); % displaying error, if found
matrix. (b) In each row that does not err = 2;
consist entirely of zeros, the leftmost else
if size(b,2) ~= 1
nonzero element is a 1 (called a leading b=b';
1 or a pivot). (c) Each column that end % end of the scope of if-else
contains a leading 1 has zeros in all other if size(b,2) ~= 1
disp('error: b is a matrix'); % displaying erron in
entries. (d) The leading 1 in any row is to matrix B
the left of any leading 1’s in the rows err = 3;
below it. end
end
3. Stop process in step 2 if you obtain a if err == 0
row whose elements are all zeros except Aa=[A,b];
the last one on the right. In that case, the for i=1:n
[Aa(i:n,i:n+1),err]=gauss_pivot(Aa(i:n,i:n+1));
system is inconsistent and has no if err == 0
solutions. Otherwise, finish step 2 and Aa(1:n,i:n+1)=gauss_jordan_step(Aa(1:n,i:n+1),i);
read the solutions of the system from the end
end
final matrix. x=Aa(:,n+1);
end
A=0;
function A1=gauss_jordan_step(A,i) % calling of fuction
function