help me with this assignment by using MATLAB. Please write your code clearly Due
ID: 3600465 • Letter: H
Question
help me with this assignment by using MATLAB.Please write your code clearly Due Sun 10/29, 11pm Implement algorithm 6.1 that accomplishes Gaussian elimination with row swap ping INPUTmber of unkoowras n; and the argament matrix A aw OUTPUT: solution Step 1: For i = 1 to n-1 do steps 2-4 Step 2: Let p be the smallest integer with i S PS n and a 0 If no integer p ean be found then outpat('no uniqae solation) STOP Step 3: If P then perform swap the p-th row and l-th row Step 4: For j=i+1 ndosteps 5 and 6 Step 5: Set ''aula“ Step 6: Perform (E-mpEj E, where E, represents jth row or jth equation Step T: If an-0then OUTPUT ('no unique solution exists): STOP Step 8: Set - Step 9: For i-1....1 Set Step 10 OUTPUT (, "z"). STOP Use the above algorit hm to solve the system of equations eri-2+2+21
Explanation / Answer
function C = gauss_elimination(A,B) % defining the function
A= [ 1 2; 4 5] % Inputting the value of coefficient matrix
B = [-1; 4] % % Inputting the value of coefficient matrix
i = 1; % loop variable
X = [ A B ];
[ nX mX ] = size( X); % determining the size of matrix
while i <= nX % start of loop
if X(i,i) == 0 % checking if the diagonal elements are zero or not
disp('Diagonal element zero') % displaying the result if there exists zero
return
end
X = elimination(X,i,i); % proceeding forward if diagonal elements are non-zero
i = i +1;
end
C = X(:,mX);
function X = elimination(X,i,j)
% Pivoting (i,j) element of matrix X and eliminating other column
% elements to zero
[ nX mX ] = size( X);
a = X(i,j);
X(i,:) = X(i,:)/a;
for k = 1:nX % loop to find triangular form
if k == i
continue
end
X(k,:) = X(k,:) - X(i,:)*X(k,j); % final result
end
function C = gauss_elimination(A,B) % defining the function
A= [ 1 2; 4 5] % Inputting the value of coefficient matrix
B = [-1; 4] % % Inputting the value of coefficient matrix
i = 1; % loop variable
X = [ A B ];
[ nX mX ] = size( X); % determining the size of matrix
while i <= nX % start of loop
if X(i,i) == 0 % checking if the diagonal elements are zero or not
disp('Diagonal element zero') % displaying the result if there exists zero
return
end
X = elimination(X,i,i); % proceeding forward if diagonal elements are non-zero
i = i +1;
end
C = X(:,mX);
function X = elimination(X,i,j)
% Pivoting (i,j) element of matrix X and eliminating other column
% elements to zero
[ nX mX ] = size( X);
a = X(i,j);
X(i,:) = X(i,:)/a;
for k = 1:nX % loop to find triangular form
if k == i
continue
end
X(k,:) = X(k,:) - X(i,:)*X(k,j); % final result
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.