xref: /petsc/src/tao/leastsquares/tutorials/matlab/more_wild_probs/jacobian.m (revision c20d77252dee0f9c80fc6f8b1a6f948e11175edb) !
1function J = jacobian(m,n,x,nprob)
2%     This subroutine computes the Jacobian of the nonlinear equations
3%     defining the benchmark problems in
4%
5%     Benchmarking Derivative-Free Optimization Algorithms
6%     Jorge J. More' and Stefan M. Wild
7%     SIAM J. Optimization, Vol. 20 (1), pp.172-191, 2009.
8%
9%     The dependencies of this function are based on executing the AD
10%     software adimat on a modified from of the dfovec function from
11%     http://www.mcs.anl.gov/~more/dfo/
12%     See the instructions of dfovec.m for additional details on these
13%     nonlinear benchmark problems (and appropriate values of m and n).
14%
15%   J = jacobian(m,n,x,nprob)
16%
17%       J is an output array of size m-by-n, with J(i,j) denoting the
18%         derivative (evaluated at x) of the ith equation with respect to
19%         the jth variable.
20%       m and n are positive integer input variables. n must not
21%         exceed m.
22%       x is an input array of length n.
23%       nprob is a positive integer input variable which defines the
24%         number of the problem. nprob must not exceed 22.
25%
26%     Argonne National Laboratory
27%     Stefan Wild. July 2014.
28
29% Initialization for adimat objects
30t = 0; g_t = 1; g_x = zeros(size(x));
31J = zeros(m,n);
32for ind = 1:n % Do one coordinate direction at a time:
33    [g_fvec, fvec] = g_dfovec_1d(g_t, t, ind, m, n, g_x, x, nprob);
34    J(:,ind) = g_fvec;
35end
36
37J(find(abs(J)) > 1e64) = NaN;
38J = sparse(J)';
39
40