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

IN MATLAB CODE: Write a function with the header [U, b2, L] = myForwardSweep(A,b

ID: 3678665 • Letter: I

Question

IN MATLAB CODE:

Write a function with the header [U, b2, L] = myForwardSweep(A,b) which performs systematic linear transformation on the augmented matrix [A|b]. Note that this function should return not only the transformed A and b, but also a matrix containing -m(i, j) used in the transformation but also with 1’s on its diagonal. Recall that m(i, j) = -A(i, j) / A(j, j) Since m will only populate with elements below the diagonal, you should first initialize m with nxn zeros. Test Cases:

>> format short

>> A = [815 98 158 142 656; 906 279 971 422 36; 127 547 958 916 850; 914 958 486 793 934; 633 965 801 960 679];

>> b = [5333; 6245; 12009; 12130; 12201];

>> [U, b2, L] = myForwardSweep(A,b)

U = 1.0e+03 *

0.8150 0.0980 0.1580 0.1420 0.6560

0 0.1701 0.7954 0.2641 -0.6932

0 0 -1.5535 0.0680 2.9154

0 0 0 -0.8436 -3.2086

0 0 0 0 -0.1374

b2 = 1.0e+04 *

0.5333

0.0317

1.0188

-1.9418

-0.0687

Explanation / Answer

function [A,b,m] = myForwardSweep(A,b) Ab = [A b]; m = zeros(length(A)); for j = 1:length(A)-1 for i = j+1:length(A) m(i,j) = -(Ab(i,j)/Ab(j,j)); Ab(i,:) = Ab(i,:)+(Ab(j,:)*m(i,j)); end end b = Ab(:,end); A = Ab(:,1:end-1); Ab end