Optimization: principles and algorithms, by Michel Bierlaire
exRosenbrock.m
Go to the documentation of this file.
1 %> \file
2 %> Rosenbrock function in \f$n\f$ dimensions.
3 %> \f[f(x)=\sum_{i=1}^{n-1} 100(x_{i+1} - x_i^2)^2 + (1-x_i)^2.\f]
4 %> If \f$n=2\f$, we have \f$f(x)=100(x_2 - x_1^2)^2 + (1-x_1)^2\f$.
5 %> The minimum is 0 at \f$x=(1,1,\ldots,1)^T\f$.
6 %> @author <a href="http://learning.eng.cam.ac.uk/carl/">Carl Edward Rasmussen</a>
7 %> @date 2001-07-21
8 %> @ingroup Examples
9 %> @ingroup chap12
10
11 %> Example presented in Section 11.6 of \cite Bier15-book
12 function [f, df, ddf] = exRosenbrock(x);
13 # Carl Edward Rasmussen, 2001-07-21.
14
15 D = length(x);
16 f = sum(100*(x(2:D)-x(1:D-1).^2).^2 + (1-x(1:D-1)).^2);
17
18 if nargout > 1
19  df = zeros(D, 1);
20  df(1:D-1) = - 400*x(1:D-1).*(x(2:D)-x(1:D-1).^2) - 2*(1-x(1:D-1));
21  df(2:D) = df(2:D) + 200*(x(2:D)-x(1:D-1).^2);
22 end
23
24 if nargout > 2
25  ddf = zeros(D,D);
26  ddf(1:D-1,1:D-1) = diag(-400*x(2:D) + 1200*x(1:D-1).^2 + 2);
27  ddf(2:D,2:D) = ddf(2:D,2:D) + 200*eye(D-1);
28  ddf = ddf - diag(400*x(1:D-1),1) - diag(400*x(1:D-1),-1);
29 end
30 endfunction
function exRosenbrock(in x)
Example presented in Section 11.6 of .