Question

Engineering Computations and Modelling > Week 6 Homework > Backward Substitution 2 solutions submitted (max: Unlimited) | Vie

and returns as output: • X, an n x 1 solution vector x Do not use backslash operator or other MATLAB solver functions to compHERE IS THE CODE I FIXED BUT STILL DOESN'T WORK

NOTE: THE VARIABLE x = zeros(size(b)) CAN'T BE CHANGED CAUSE HAS BEEN SET BY ASSESSOR

Function C Reset LOMATLAB Documentation 1 function x = backsub(u,b) 2 3 % Initialize the output vector. 4 n = length(b); 5 x

HI EXPERTS I NEED HELP TO SOLVE THIS HOMEWORK PROBLEM FOR MATLAB CODE

A COUPLE OF TIMES I TRIED LAST TIME TO ASK BUT ALL OF THE ANSWERS WERE WRONG

PLEASE KINDLY HELP ME FIND THE RIGHT SOLUTION, ANY HELP WILL BE VERY APPRECIATE

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

Ok, your algorithm is a bit off the mark. You were thinking along the right paths, however. For these kinds of problems, the best way to learn is to do the steps by hand and then thinking about how you will implement them via code.

I have provided both the text and the screenshot for your better understanding. The screenshot also has some comments for your help. Please note that this is a script file which is to be saved as backsub.m in your MATLAB root directory.
The script backsub.m gives the value of the variable matrix as output. The input must be a square upper triangular non-singular matrix with none of the diagonal elements as 0.

backsub.m

+ backsub.m function x = backsub (U,b) n = length(b); Scalculating size of solution vector x = ones (size (b)); $initializing

function x = backsub(U,b)

n = length(b); %calculating size of solution vector
x = ones(size(b)); %initializing solution vector

for i=n:-1:1
x(i) = b(i)/U(i,i); %solving the last row of the matrix
b(1:i-1) = b(1:i-1) - U(1:i-1,i)*x(i); %updating the constant values so that the previous row can now be treated as the last row of the matrix
end
fprintf("result of backward substitution\n");
disp(x);
end

OUTPUT

I have attached screenshots for 3 random test cases, one of them in the question and the other 2 from random sources.

Example matrix in question

>> A = [1,2;0,2] 2 1 2 0 >> B = [2;1] B = 1 >> x = backsub (A,B); result of backward substitution 1.0000 0.5000 fx >> |

3x3 matrix>> A = [1,-2,1;0,1,6;0,0,1] 1 6 -2 1 0 >> b = [ 4;-1;2] b = 4 2 >> x = backsub (A,b) result of backward substitution -24 -13

4x4 matrix>> A = [ 1,2,1,-1 ; 0,-4,1,7;0,0,-2,1;0,0,0,-1] 1 1 -1 7 1 1 2 0 -4 0 -2 0 0 0 >> B = [5;1;1;3] B = 5 -1 1 1 3 >> x = backsub


*A humble request* - If you have any doubt, please use the comment section to communicate. This will clarify your doubt, and also help me to get better at answering your next questions. At the same time, If my answer helped you, please consider leaving an upvote. I hope you understand my viewpoint. Thank you :)

Add a comment
Know the answer?
Add Answer to:
HERE IS THE CODE I FIXED BUT STILL DOESN'T WORK NOTE: THE VARIABLE x = zeros(size(b))...
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