Optimization: principles and algorithms, by Michel Bierlaire
secantOneVariable.m
Go to the documentation of this file.
1 %> \file
2 %> Algorithm 8.2: Newton's secant method, one variable. Implementation of algorithm 8.2 of \cite Bier15-book
3 %>
4 %> @author <a href="http://people.epfl.ch/michel.bierlaire">Michel Bierlaire</a>
5 %> @date Thu Mar 19 09:53:09 2015
6 %> @ingroup Algorithms
7 %> @ingroup chap08
8 
9 %> @note Tested with \ref run0703sec.m
10 
11 %> Applies Newton's secant algorithm 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 a0 the first approximation of the derivative
15 %> @param eps algorithm stops if \f$|F(x)| \leq \varepsilon \f$.
16 %> @param maxiter maximum number of iterations (Default: 100)
17 %> @return root of the function
18 function solution = secantOneVariable(obj,x0,a0,eps,maxiter=100)
19  xk = x0 ;
20  ak = a0 ;
21  f = feval(obj,xk) ;
22  k = 0 ;
23  printf("%d %15.8e %15.8e %15.8e\n",k,xk,f,ak) ;
24  do
25  xold = xk ;
26  xk = xk - f / ak ;
27  fold = f ;
28  f = feval(obj,xk) ;
29  ak = (fold - f) / (xold - xk) ;
30  k=k+1;
31  printf("%d %15.8e %15.8e %15.8e\n",k,xk,f,ak) ;
32  until (abs(f) <= eps || k >= maxiter)
33  solution = xk ;
34 endfunction
function secantOneVariable(in obj, in x0, in a0, in eps, in maxiter)
Applies Newton&#39;s secant algorithm to solve where .
Copyright 2015-2016 Michel Bierlaire