Backward Substitution in MATLAB
Backward Substitution
Consider a Upper Triangular matrix U of dimension n, U x = b
[u1,1u1,2…u1,n0u2,2…u2,n⋮⋮⋱⋮00…un,n][x1x2⋮xn]=[b1b2⋮bn]
Solving Procedure:
- xn=bnun,n
- Moving to n−1th row, there are two coefficients related to xn(already known) and xn−1 (unkown).
un−1,n−1xn−1+un−1,nxn=bn−1
- Solving for unknown xn, we have
xn−1=bn−1−un−1,nxnun−1,n−1
- Generalizing for ith row,
xi=1ui,i(bi−n∑j=i+1ui,jxj)
A MATLAB function to solve upper triangular system is provided. This process is also known as 'backward substitution'
function X = backwardsubstitution(U,B) % Input U = Upper triangular matrix % B = Right hand vector (force vector) % Output X = solution vector (output vector) n = size(U,1); % n = rank of matrix U for i = n:-1:1 % loops to move from last row to first row sum = 0; for j = i+1:n sum = sum + U(i,j)*X(j)/U(i,i); end X(i) = B(i)/U(i,i) - sum; end A = [5 2 4; 0 3 2; 0 0 1]; B = [10; -2; -2]; x = backwardsubstitution(A,B)
x = 3.3333 0.6667 -2.0000
Comments
Post a Comment
If you have any doubts, please let me know!