From: Bjørn Rustad Date: Fri, 30 Sep 2011 19:04:55 +0000 (+0200) Subject: Rename newtsteep X-Git-Url: http://git.rustad.me/?a=commitdiff_plain;h=7ad019e4c45583a17c650d4443457e2bf6d3b7b0;p=nummat1 Rename newtsteep --- diff --git a/steepestnewton.py b/steepestnewton.py new file mode 100644 index 0000000..2498575 --- /dev/null +++ b/steepestnewton.py @@ -0,0 +1,23 @@ +from newton import newton +from steepest import steepest +from function import gradient_g +from numpy.linalg import norm + +# Run steepest method until tolerance steep_tol, then continue with Newtons +# method until tolerance newt_tol +def steepestnewton(x0, H, b, c, steep_tol, newt_tol): + x = [] + r = [] + + # Use the starting norm to calculate relative residuals in both algorithms + x0_norm = norm(gradient_g(x0, H, b, c)) + points, residuals = steepest(x0, H, b, c, steep_tol, 100, 0, x0_norm) + x.extend(points) + r.extend(residuals) + + # Newton starts in the same point as steepest ends in + points, residuals = newton.newton(x[len(x)-1], H, b, c, newt_tol, 100, x0_norm) + x.extend(points[1:]) + r.extend(residuals[1:]) + + return (x, r)