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

PROGRAMMING IN MATLAB Write a function with the header [U, b2, L] = myForwardSwe

ID: 1719250 • Letter: P

Question

PROGRAMMING IN MATLAB

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.0000 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

L =

1.0000 0 0 0 0

1.1117 1.0000 0 0 0

0.1558 3.1268 1.0000 0 0

1.1215 4.9871 2.3545 1.0000 0

0.7767 5.2270 2.2395 0.8098 1.0000

>> L*U

ans =

815.0000 98.0000 158.0000 142.0000 656.0000

906.0000 279.0000 971.0000 422.0000 36.0000

127.0000 547.0000 958.0000 916.0000 850.0000

914.0000 958.0000 486.0000 793.0000 934.0000

633.0000 965.0000 801.0000 960.0000 679.0000

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

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