[10pt] Implement backward substitution to solve systems Uz b, i.e., write a func
ID: 3586648 • Letter: #
Question
[10pt] Implement backward substitution to solve systems Uz b, i.e., write a function x = backward(A, b), which expects as inputs an upper triangular matrix U E Rnxn, and a right hand side vector bE Rn, which returns the solution vector ER. The function should find the size n from the vector b and also check if the matrix and the vector sizes are compatible before it starts to solve the system. Please hand in your code. Apply your program for the computation of for x ER4, with 1 2 6 -1 -3 0 0 4-1 0 0 02Explanation / Answer
octave:1> U=[1 2 6 -1;0 3 1 0;0 0 4 -1; 0 0 0 2]
U =
1 2 6 -1
0 3 1 0
0 0 4 -1
0 0 0 2
octave:2> b=[-1;-3;-2;4]
b =
-1
-3
-2
4
octave:3> nLength = length( b );
octave:4> nLength
nLength = 4
octave:5> x = zeros( nLength, 1 );
octave:6> for i=nLength:-1:1
x(i) = ( b(i) - U(i, :)*x )/U(i, i);
end
octave:7> x
x =
3
-1
0
2
The matlab code takes given U matrix and b matrix.
nLength calculates the length of the matrix b
x is the zeros(nLength,1) according to the backsubstitution algorithm
Run a loop to calculate the x value
Execute the command accordingly to get the output.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.