import numpy as np
n = 5
A = np.random.randn(n, n) * np.tri(n).T
print(A)
x = np.random.randn(n)
print(x)
b = np.dot(A, x)
xcomp = np.zeros(n)
for i in range(n-1, -1, -1):
tmp = b[i]
for j in range(n-1, i, -1):
tmp -= xcomp[j]*A[i,j]
xcomp[i] = tmp/A[i,i]
Now compare the computed $x$ against the reference solution.
print(x)
print(xcomp)
Questions/comments: