docstr: Improve a solution to a linear equation system iteratively.
  
  This re-uses the LU decomposition and is thus cheap.
  Usually 3 up to 4 iterations are giving the maximal improvement.
docstr_tok: ["Improve","a","solution","to","a","linear","equation","system","iteratively",".","This","re-uses","the","LU","decomposition","and","is","thus","cheap",".","Usually","3","up","to","4","iterations","are","giving","the","maximal","improvement","."]
code: def improve_solution(ctx, A, x, b, maxsteps=1):
      """
      Improve a solution to a linear equation system iteratively.
  
      This re-uses the LU decomposition and is thus cheap.
      Usually 3 up to 4 iterations are giving the maximal improvement.
      """
      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
  
imports: from copy import copy
  from ..libmp.backend import xrange
label_desc: Use image node_id 5 for calling the LinearAlgebraMethods obj's underlying member method code with example usage: obj.improve_solution(ctx, A, x, b, maxsteps) and returns: x