Optimization: principles and algorithms, by Michel Bierlaire
newtonNVariables.m
Go to the documentation of this file.
1 %> \file
2 %> Algorithm 7.3: Newton's method, n variables. Implementation of algorithm 7.3 of \cite Bier15-book
3 %>
4 %> @author <a href="http://people.epfl.ch/michel.bierlaire">Michel Bierlaire</a>
5 %> @date Wed Mar 18 21:47:57 2015
6 %> @ingroup Algorithms
7 %> @ingroup chap07
8 
9 %> @note Tested with \ref run0711.m
10 %> @note Tested with \ref run0712.m
11 
12 %> Applies Newton's algorithm to solve \f$F(x)=0\f$ where \f$F:\mathbb{R}^n\to\mathbb{R}^n \f$
13 %> @param obj the name of the Octave function defining F(x) and its Jacobian
14 %> @param x0 the starting point
15 %> @param eps algorithm stops if \f$\|F(x)\| \leq \varepsilon \f$.
16 %> @param maxiter maximum number of iterations (Default: 100)
17 %> @return [solution,f] solution: root of the function, f: value of F at the solution
18 function [solution,f] = newtonNVariables(obj,x0,eps,maxiter=100)
19  xk = x0 ;
20  [f,J] = feval(obj,xk) ;
21  k = 0 ;
22  printf("%d %15.8e %15.8e %15.8e\n",k,xk(1),f(1),norm(f)) ;
23  printf(" %15.8e %15.8e\n",xk(2),f(2)) ;
24  do
25  xk = xk - J \ f ;
26  [f,J] = feval(obj,xk) ;
27  k=k+1;
28  printf("%d %15.8e %15.8e %15.8e\n",k,xk(1),f(1),norm(f)) ;
29  printf(" %15.8e %15.8e\n",xk(2),f(2)) ;
30  until (norm(f) <= eps || k >= maxiter)
31  solution = xk ;
32 endfunction
function newtonNVariables(in obj, in x0, in eps, in maxiter)
Applies Newton&#39;s algorithm to solve where .
Copyright 2015-2018 Michel Bierlaire