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