1 answer

HERE IS THE CODE I FIXED BUT STILL DOESN'T WORK NOTE: THE VARIABLE x = zeros(size(b))...

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

Engineering Computations and Modelling > Week 6 Homework > Backward Substitution 2 solutions submitted (max: Unlimited) | View my solutions Problem Summary Consider the matrix problem Ux=b, where U is an upper triangular matrix and b is a column vector with the form: U11 U12 U13 U in bi 0 Uan b2 U22 U23 0 U33 U= 0 Uzn b= |b3 . ... ... ... ... 0 0 0 bn This problem can be solved using a simple algorithm called backward substitution. In this algorithm, xn is easily solved from the last equation in the matrix problem. This result is then substituted into the second to last equation, which is then explicitly solved for xn-1. This process is repeated until all values of x are found. Complete the definition of the backsub function below by implementing the backward substitution algorithm. This function takes as input: U, an nxn upper triangular matrix b, an nx 1 vector for the right-hand-side of the matrix equation
and returns as output: • X, an n x 1 solution vector x Do not use backslash operator or other MATLAB solver functions to compute the output. A simple test case has been provided to test your solution before submitting. Fix This Solution Best Solution My Solutions Test Results Solution 1: 1 of 3 tests passed Submitted on 20 Apr 2020 | ID: 21477073 | Size: 61 1 function x = backsub(0,b) 2 3 % Initialize the output vector. 4 n = length(b); 5 x = zeros(size(b)); 6 7 % Do the backward substitution below. 8 for i = n:-1:1 9 x(i) = (b(i) - U(i, i+1:n)*x(i+1:n))/(i, i) 10 end
Function C Reset LOMATLAB Documentation 1 function x = backsub(u,b) 2 3 % Initialize the output vector. 4 n = length(b); 5 x = zeros(size(b)); 6 7 % Do the backward substitution below. 8 for i = n:-1:1 9 S = 0 10 for j = 1:n 11 S = S + U(i, j)*x(j) 12 end 13 S = S - U(i, i)*x(i) 14 x(i) = (b(i) - s)/(i, i) 15 end 16 Code to call your function ® C Reset 1 U = [1 2;0 2]; 2 b = [2;1]; 3 X = backsub(0, b)

Answers

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 :)

.

Similar Solved Questions

1 answer
Find the function (fo h) and simplify. f(x) = 7x + 10, h(x) = Vx+6 (fo...
Find the function (fo h) and simplify. f(x) = 7x + 10, h(x) = Vx+6 (fo h)(x) = 12 (Simplify your answer.)...
1 answer
Required information Use the following information for the Exercises below. [The following information applies to the...
Required information Use the following information for the Exercises below. [The following information applies to the questions displayed below) Ramirez Company installs a computerized manufacturing machine in its factory at the beginning of the year at a cost of $48,400. The machine's useful li...
1 answer
A firm’s marginal cost decreases when it has _______ and its long run average total cost...
A firm’s marginal cost decreases when it has _______ and its long run average total cost decreases when it has _______. A. diminishing marginal returns, decreasing returns to scale B.diminishing marginal returns, increasing returns to scale C. diminishing marginal returns, economies of scope D...
1 answer
In the coordinate plane, line "m" is the reflection of line "l" about the x axis. If the slope of line "m" is - 4/5 what is the slope of line ?
In the coordinate plane, line "m" is the reflection of line "l" about the x axis. If the slope of line "m" is - 4/5 what is the slope of line ?...
1 answer
PLEASE HELP! Calculating density given % by mass and molar? Thank you so much! Sulfuric acid is H2SO4. A sulfuric acid s...
PLEASE HELP! Calculating density given % by mass and molar? Thank you so much! Sulfuric acid is H2SO4. A sulfuric acid solution is 10.78M and it is 67.0% by mass. Calculate its density....
1 answer
I need help completing part B only please!! Exercise 9-11A Calculating employee and employer payroll taxes...
I need help completing part B only please!! Exercise 9-11A Calculating employee and employer payroll taxes LO 9-5 Sky Co. employed Tom Mils in Year 1. Tom earned $5,100 per month and worked the entire year. Assume the Social Security tax rate is 6 percent for the first $110,000 of earnings, and th...
1 answer
How do you factor #64x ^2 - 49#?
How do you factor #64x ^2 - 49#?...
1 answer
Objectives: Use strings and string library functions. Write a program that asks the user to enter...
Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an ...
1 answer
Answer: cout << k/(i+j) Q1) Provide code that outputs a random number 10 through 20? Q2)...
Answer: cout << k/(i+j) Q1) Provide code that outputs a random number 10 through 20? Q2) Provide code that outputs a random character 'a' through ‘y'? Q3) Using char c = 'A'; Output “BCD” without changing the value of c. Q2) Provide code that outputs a ran...
1 answer
16. We said that MHC2 is mainly for presentation of exogenous antigens, whereas MHC1 is mainly...
16. We said that MHC2 is mainly for presentation of exogenous antigens, whereas MHC1 is mainly for presentation of endogenous antigens. Why is this so? A. MHC2 is on the outside of cells, MHC1 is on the inside. B. MHC2 binds to bacteria to allow macrophages to engulf the bacteria. C. MHC1 is found i...
1 answer
A 11.56 g mixture of sugar (C_12H_22O_M) and table salt (NaCl) is dissolved in 203 g...
A 11.56 g mixture of sugar (C_12H_22O_M) and table salt (NaCl) is dissolved in 203 g of water. The freezing point of the solution was measured as -2 57 degree C Calculate the mass percent of sugar in the mixture. A list of K_t values can be found here....
1 answer
Please show all equations used, thanks. A 5.7 gram piano wire spans 42.0 cm. To what...
please show all equations used, thanks. A 5.7 gram piano wire spans 42.0 cm. To what tension must this wire be stretched to ensure that its fundamental mode vibrates at the D, note (f 293.7 Hz)? (Enter your answer in in N.) Need Help?...
1 answer
Linear Programming (MULTIPLE CHOICE)
Breezeless Company produces doors and window frames. It generates profit at $2.00 per door and $1.00 per window frame. Manufacture of these products requires twowork centers. Work center 1 has 120 labor hours available while work center 2 has 80 hours available. Production of one hundred doors requi...
1 answer
2 Tace the path of a drop of venous blood from the left ankle to the...
2 Tace the path of a drop of venous blood from the left ankle to the right side of the brain...
1 answer
18. As glucose is catabolized, the energy is captured by: a. forming ADP and by oxidizing...
18. As glucose is catabolized, the energy is captured by: a. forming ADP and by oxidizing adenine dinucleotides b. forming ATP and by oxidizing adenine dinucleotides c. forming ADP and by reducing adenine dinucleotides d. forming ATP and by reducing adenine dinucleotides e. forming ATP and by transf...
1 answer
I need to find the percent of the total area of New York City that each borough covers
I need to find the percent of the total area of New York City that each borough covers. Bronx 41miles Manhattan 23 miles Queens 110 miles Brooklyn 73 miles Staten Island 56 miles Not sure how to figure it?...
1 answer
A characteristic that is displayed according to a species sex is referred to as a __________________________...
A characteristic that is displayed according to a species sex is referred to as a __________________________ (two words) character. Note: The answer is not: Sex Linked or Sex Limited.  ...
1 answer
Ho me/ h171113 Areas of shapes on grids Do 4 proble Can u help O Send...
ho me/ h171113 Areas of shapes on grids Do 4 proble Can u help O Send a chat...