source: trunk/test_more/rev_two.cpp @ 2354

Last change on this file since 2354 was 1370, checked in by bradbell, 11 years ago

trunk: Fix svn_add_id.sh and use it set Id property for some missed files.

  • Property svn:keywords set to Id
File size: 1.3 KB
Line 
1/* $Id: rev_two.cpp 1370 2009-05-31 05:31:50Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-06 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Common Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12# include <cppad/cppad.hpp>
13
14bool RevTwo()
15{       bool ok = true;
16        using CppAD::AD;
17        using CppAD::vector;
18        using CppAD::NearEqual;
19
20
21        size_t n = 2;
22        vector< AD<double> > X(n);
23        X[0] = 1.;
24        X[1] = 1.;
25        Independent(X);
26
27        size_t m = 1;
28        vector< AD<double> > Y(m);
29        Y[0] = X[0] * X[0] + X[0] * X[1] + 2. * X[1] * X[1];
30        CppAD::ADFun<double> F(X,Y);
31
32        vector<double> x(n);
33        x[0] = .5;
34        x[1] = 1.5;
35
36        size_t L = 1;
37        vector<size_t> I(L);
38        vector<size_t> J(L);
39        vector<double> H(n);
40        I[0] = 0;
41        J[0] = 0;
42        H    = F.RevTwo(x, I, J);
43        ok  &= NearEqual(H[0], 2., 1e-10, 1e-10);
44        ok  &= NearEqual(H[1], 1., 1e-10, 1e-10);
45        J[0] = 1;
46        H    = F.RevTwo(x, I, J);
47        ok  &= NearEqual(H[0], 1., 1e-10, 1e-10);
48        ok  &= NearEqual(H[1], 4., 1e-10, 1e-10);
49
50        return ok;
51}
Note: See TracBrowser for help on using the repository browser.