In this experiment we will look at both the residual and the error of a calculation using a direct solver.

First set up a problem:

In [4]:
import scipy as sp
import numpy as np
import numpy.linalg as nla
In [21]:
n = 10
A = np.random.rand(n,n)
xstar = np.ones((n,))
b = A.dot(xstar)
for i in range(2):
    A = A.dot(A)
In [22]:
print("Cond(A)=",nla.cond(A))
Cond(A)= 141885.087429
In [23]:
x = nla.solve(A, b)
In [24]:
print("||r|| = ", nla.norm(b-A.dot(x)))
print("||e|| = ", nla.norm(xstar-x))
||r|| =  7.52027806292e-13
||e|| =  26.4803014532

Here we can see that since the condition number is high, a small residual does not lead to a small error.

In [ ]: