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>
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
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
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/>.
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 %%================================
38 %% dfxpdp is more general and is meant to be used instead of dfdp in
41 function prt = dfdp (x, f, p, dp, func, bounds)
43 %% This is just an interface. The original code has been moved to
44 %% __dfdp__.m, which is used with two different interfaces by
47 %% if (ischar (varargin{5}))
48 %% varargin{5} = @ (p) str2func (varargin{5}) (varargin{1}, p);
50 %% varargin{5} = @ (p) varargin{5} (varargin{1}, p);
54 func = @ (p) str2func (func) (x, p);
56 func = @ (p) func (x, p);
62 hook.lbound = bounds(:, 1);
63 hook.ubound = bounds(:, 2);
66 hook.diffp = abs (dp);
68 hook.diff_onesided = dp < 0;
70 prt = __dfdp__ (p, func, hook);