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

4. (10 points) Write a function with the header ly] mysub (L, b) which solves Ly

ID: 3679394 • Letter: 4

Question


4. (10 points) Write a function with the header ly] mysub (L, b) which solves Ly b for y given an nxn lower triangular matrix L and an nx1 vector b. Use nested for loops, do not use built in Matlab functions, inv, pinv, 1. Test Case 1.0000 1.1117 1.0000 0.1558 3.1268 1.0000 1.1215 4.9871 2.3545 1.0000 0.7767 5.2270 2.2395 0.8098 1.0000 E202 Dr. Charles Negus omputer Programming Applications for Mechanical Engineers bNew [10666 124 90; 24018 24260 24 402 J; y my Sub (L bNew) 1.0e+04 0666 0633 0376 8835 0.1374

Explanation / Answer

Hi i have written the sample function for your reference,

function L(y) = b

%LU Triangular factorization

% L(y)= b produces a unit lower triangular

% matrix L, an upper triangular matrix U, and a

% permutation vector p, so that L*U = A(p,:).

[n,n] = size(A);

p = (1:n)’

for k = 1:n-1

% Find largest element below diagonal in k-th column

[r,m] = max(abs(A(k:n,k)));

m = m+k-1;

% Skip elimination if column is zero

if (A(m,k) ~= 0)

% Swap pivot row

if (m ~= k)

A([k m],:) = A([m k],:);

p([k m]) = p([m k]);

end

% Compute multipliers

i = k+1:n;

A(i,k) = A(i,k)/A(k,k);

% Update the remainder of the matrix

j = k+1:n;

A(i,j) = A(i,j) - A(i,k)*A(k,j);

end

end

% Separate result

L = tril(A,-1) + eye(n,n);

U = triu(A);

Study this function carefully. Almost all the execution time is spent in the statement

A(i,j) = A(i,j) - A(i,k)*A(k,j);

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