def a_fun_jacobian_xam() : # # load the Cppad Swig library import py_cppad # # initialize return variable ok = True # --------------------------------------------------------------------- # number of dependent and independent variables n_dep = 1 n_ind = 3 # # create the independent variables ax x = py_cppad.vec_double(n_ind) for i in range( n_ind ) : x[i] = i + 2.0 # ax = py_cppad.independent(x) # # create dependent variables ay with ay0 = ax_0 * ax_1 * ax_2 ax_0 = ax[0] ax_1 = ax[1] ax_2 = ax[2] ay = py_cppad.vec_a_double(n_dep) ay[0] = ax_0 * ax_1 * ax_2 # # define af corresponding to f(x) = x_0 * x_1 * x_2 af = py_cppad.a_fun(ax, ay) # # compute the Jacobian f'(x) = ( x_1*x_2, x_0*x_2, x_0*x_1 ) fp = af.jacobian(x) # # check Jacobian x_0 = x[0] x_1 = x[1] x_2 = x[2] ok = ok and fp[0 * n_ind + 0] == x_1 * x_2 ok = ok and fp[0 * n_ind + 1] == x_0 * x_2 ok = ok and fp[0 * n_ind + 2] == x_0 * x_1 # return( ok ) #