Question

Complete the definition of the backsub function below by implementing the backward substitution algorithm. This function...

Complete the definition of the backsub function below by implementing the backward substitution algorithm. This function takes as input:

  • U, an n x n upper triangular matrix
  • b, an n x 1 vector for the right-hand-side of the matrix equation

and returns as output:

  • x, an n x 1 solution vector x

function x = backsub(U,b)

% Initialize the output vector. This will speed up computation by pre-allocating the memory.

n = length(b);

x = zeros(size(b));

% Do the backward substitution below. It should work for any size uppertriangular matrix [U].

x(n) = b(n)/U(n,n);

for i = n-1:-1:1

end

end

U = [1 2;0 2];

b = [2;1];

x = backsub(U,b)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

U = [1 2;0 2];

b = [2;1];

x = backsub(U,b)


function x = backsub(U,b)

% Initialize the output vector. This will speed up computation by pre-allocating the memory.

n = length(b);

x = zeros(size(b));

% Do the backward substitution below. It should work for any size uppertriangular matrix [U].

x(n) = b(n)/U(n,n);

for i = n:-1:1
x(i) = b(i)/U(i,i);
b(1:i-1)=b(1:i-1)-U(1:i-1,i)*x(i);
end

end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Complete the definition of the backsub function below by implementing the backward substitution algorithm. This function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT