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