-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineSearchND.m
45 lines (40 loc) · 1.06 KB
/
lineSearchND.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function [xmin fret] = lineSearchND(fun, x0, dir, tol)
%LINESEARCHND Multidimensional line search
%
% Usage
% XMIN = lineSearchND(FUN, X0, DIR, TOL)
%
% Description
% FUN is the function to minimize. It accepts a row vector as input, and
% returns a scalar.
% X0 is the initial guess of the minimum. It is a 1-by-N row vector.
% DIR is the direction seach. It is a 1-by-N row vector.
% TOL is the tolerance used by brentLineSearch.
%
%
% calls the brentLineSearch function.
%
% Example
% lineSearchND
%
% See also
% brentLineSearch
%
% ------
% Author: David Legland
% e-mail: [email protected]
% Created: 2010-08-08, using Matlab 7.9.0.529 (R2009b)
% Copyright 2010 INRA - Cepia Software Platform.
% use a function handle of 1 variable
fun1 = @(t) fun(x0 + t*dir);
% guess initial bounds of the function
ax = -1;
bx = 1;
[ax bx cx] = fMinBracket(fun1, ax, bx);
% search minimum along dimension DIR
tmin = brentLineSearch(fun1, ax, bx, cx, tol);
% construct new optimal point
xmin = x0 + tmin*dir;
if nargout>1
fret = fun(xmin);
end