]> Creatis software - CreaPhase.git/blob - octave_packages/optim-1.2.0/dfdp.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / optim-1.2.0 / dfdp.m
1 %% Copyright (C) 1992-1994 Richard Shrager
2 %% Copyright (C) 1992-1994 Arthur Jutan
3 %% Copyright (C) 1992-1994 Ray Muzic
4 %% Copyright (C) 2010, 2011 Olaf Till <i7tiol@t-online.de>
5 %%
6 %% This program is free software; you can redistribute it and/or modify it under
7 %% the terms of the GNU General Public License as published by the Free Software
8 %% Foundation; either version 3 of the License, or (at your option) any later
9 %% version.
10 %%
11 %% This program is distributed in the hope that it will be useful, but WITHOUT
12 %% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 %% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 %% details.
15 %%
16 %% You should have received a copy of the GNU General Public License along with
17 %% this program; if not, see <http://www.gnu.org/licenses/>.
18
19 %% function prt = dfdp (x, f, p, dp, func[, bounds])
20 %% numerical partial derivatives (Jacobian) df/dp for use with leasqr
21 %% --------INPUT VARIABLES---------
22 %% x=vec or matrix of indep var(used as arg to func) x=[x0 x1 ....]
23 %% f=func(x,p) vector initialsed by user before each call to dfdp
24 %% p= vec of current parameter values
25 %% dp= fractional increment of p for numerical derivatives
26 %%      dp(j)>0 central differences calculated
27 %%      dp(j)<0 one sided differences calculated
28 %%      dp(j)=0 sets corresponding partials to zero; i.e. holds p(j) fixed
29 %% func=function (string or handle) to calculate the Jacobian for,
30 %%      e.g. to calc Jacobian for function expsum prt=dfdp(x,f,p,dp,'expsum')
31 %% bounds=two-column-matrix of lower and upper bounds for parameters
32 %%      If no 'bounds' options is specified to leasqr, it will call
33 %%      dfdp without the 'bounds' argument.
34 %%----------OUTPUT VARIABLES-------
35 %% prt= Jacobian Matrix prt(i,j)=df(i)/dp(j)
36 %%================================
37 %%
38 %% dfxpdp is more general and is meant to be used instead of dfdp in
39 %% optimization.
40
41 function prt = dfdp (x, f, p, dp, func, bounds)
42
43   %% This is just an interface. The original code has been moved to
44   %% __dfdp__.m, which is used with two different interfaces by
45   %% leasqr.m.
46
47   %% if (ischar (varargin{5}))
48   %%   varargin{5} = @ (p) str2func (varargin{5}) (varargin{1}, p);
49   %% else
50   %%   varargin{5} = @ (p) varargin{5} (varargin{1}, p);
51   %% end
52
53   if (ischar (func))
54     func = @ (p) str2func (func) (x, p);
55   else
56     func = @ (p) func (x, p);
57   end
58
59   hook.f = f;
60
61   if (nargin > 5)
62     hook.lbound = bounds(:, 1);
63     hook.ubound = bounds(:, 2);
64   end
65
66   hook.diffp = abs (dp);
67   hook.fixed = dp == 0;
68   hook.diff_onesided = dp < 0;
69
70   prt = __dfdp__ (p, func, hook);