Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use MATLAB for this assignment Please follow the steps and write your code clear

ID: 3601379 • Letter: U

Question

Use MATLAB for this assignment
Please follow the steps and write your code clearly Due Sun 10/29, 11pm Implement algorithm 6.1 that accomplishes Gaussian elimination with row swap ping. INPUT mllmler of unknowns n; and the argument matrix A = layl, where OUTPUT: solation Step 1: For i- 1 to n-1 do steps 2-4 Step 2: Let p be the smallest integer with i p n and Spi0. If no integer p can be found then output (no uniqae solution') STO Step 3: If then perform swap the p-th row and i-th row Step 4: For j =i+1, nclo steps 5 and 6 Step 5:Set m-aa Step 6: Perform (E,-my,E,) E, where E, represents j-th row orj-th equation Step 7: If athen OUTPUT('no unique solation exists): STOP Step 8: Set zn =@n,n+1/amn. Step 9; For i-n-1, ISet z.-lai,n+1 _ ..+1@yz,] /@w Step 10 OUTPUT (zi,Z2, z"). STOP Use the above algorithm to solve the system of equations

Explanation / Answer

Matlab function GaussianElimination_Row_Swaping.m

function x = GaussianElimination_Row_Swaping(A)
% Matlab program to solve system of equation using Gaussian Elimination
% with row swaping
[n1,n2] = size(A); % Get the size of the input array
x = zeros(1,n1); % initilizing the solution vector
for i = 1:n1 -1 % Step 1 For i = 1 to n-1 do step 2 - 4
    % Step 2: let p be the smallest integer with i<= p<= n and A(p,i) != 0
    p = i;
    while(A(p,i)== 0 && p<= n1)
        p = p+1;
    end
    % if no integer can be found then output no unique solution
    if p > n1
        fprintf('No unique solution ');
        return;
    end
    % Step 3: id p!= i then interchange pth and ith row
    if p~=i
        T = A(p,:);
        A(p,:) = A(i,:);
        A(i,:) = T;
    end
    % Step 4: For j = i+1 to n fo step 5 and 6
    for j = i+1:n1
        % Step 5: set m(j,i) = a(j,i)/a(i,i)
        m(j,i) = A(j,i)/A(i,i);
        % Step 6: Perform Aj = (Aj-m(j,i)*Ai)
        A(j,:) = A(j,:)-m(j,i)*A(i,:);
    end
end
% Step 7: if a(n,n) is zero print No unique solution
if A(n1,n1) == 0
    fprintf('No unique solution ');
    return;
end
% Step 8: set xn = a(n,n+1)/a(n,n)
x(n1) = A(n1,n2)/A(n1,n1);
% Step 9: for i = n-1 to 1 set x xi = 9a(i,n+1) - sum j - i+1 to n
% a(i,j)*x(j))/a(i,i)
for i = n1-1:-1:1
    sum = 0;
    for j = i+1:n1
        sum = sum + A(i,j)*x(j);
    end
    x(i) = (A(i,n2)-sum)/A(i,i);
end
% Step 10: solution is in x
end

Calling the function

>> A = [pi -2^0.5 -1 1 0;
        eps -1 1 2 1;
        1 1 -3^0.5 1 2;
        -1 -1 1 -5^0.5 3];
>> x = GaussianElimination_Row_Swaping(A)

x =

   -6.4507   -7.5028   -8.6042    1.0507

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote