def improve_solution(ctx, A, x, b, maxsteps=1):
        if A.rows != A.cols:
            raise RuntimeError("need n*n matrix") # TODO: really?
        for _ in xrange(maxsteps):
            r = ctx.residual(A, x, b)
            if ctx.norm(r, 2) < 10*ctx.eps:
                break
            # this uses cached LU decomposition and is thus cheap
            dx = ctx.lu_solve(A, -r)
            x += dx
        return x
Improve a solution to a linear equation system iteratively.
dataset/ETHPy150Open fredrik-johansson/mpmath/mpmath/matrices/linalg.py/LinearAlgebraMethods.improve_solution