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