def backward_substitution(upper_triangle, variable, constant, K):
 copy_upper_triangle = copy.deepcopy(upper_triangle)
 nrow = len(copy_upper_triangle)
 result = []
 for i in reversed(range(nrow)):
  a = K.zero
  for j in reversed(range((i + 1), nrow)):
   a += (copy_upper_triangle[i][j] * variable[j][0])
  variable[i][0] = ((constant[i][0] - a) / copy_upper_triangle[i][i])
 return variable

def backward_substitution ( upper_triangle , variable , constant , K ) : copy_upper_triangle = copy . deepcopy ( upper_triangle ) nrow = len ( copy_upper_triangle ) result = [ ] for i in reversed ( range ( nrow ) ) : a = K . zero for j in reversed ( range ( ( i + 1 ) , nrow ) ) : a += ( copy_upper_triangle [ i ] [ j ] * variable [ j ] [ 0 ] ) variable [ i ] [ 0 ] = ( ( constant [ i ] [ 0 ] - a ) / copy_upper_triangle [ i ] [ i ] ) return variable
performs forward substitution given a lower triangular matrix .