source: trunk/test_more/neg.cpp @ 1524

Last change on this file since 1524 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.8 KB
Line 
1/* $Id: neg.cpp 1370 2009-05-31 05:31:50Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 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
13/*
14old example and test now only used for testing
15*/
16// BEGIN PROGRAM
17
18# include <cppad/cppad.hpp>
19
20bool Neg(void)
21{       bool ok = true;
22
23        using namespace CppAD;
24
25        // independent variable vector, indices, values, and declaration
26        CPPAD_TEST_VECTOR< AD<double> > U(2);
27        size_t s = 0;
28        size_t t = 1;
29        U[s]     = 3.;
30        U[t]     = 4.;
31        Independent(U);
32
33        // dependent variable vector and indices
34        CPPAD_TEST_VECTOR< AD<double> > Z(1);
35        size_t x = 0;
36
37        // dependent variable values
38        Z[x] = - U[t];   //  - AD<double>
39
40        // create f: U -> Z and vectors used for derivative calculations
41        ADFun<double> f(U, Z);
42        CPPAD_TEST_VECTOR<double> v( f.Domain() );
43        CPPAD_TEST_VECTOR<double> w( f.Range() );
44
45        // check values
46        ok &= ( Z[x] == -4. );
47
48        // forward computation of partials w.r.t. s
49        v[s] = 1.;
50        v[t] = 0.;
51        w    = f.Forward(1, v);
52        ok &= ( w[x] == 0. );   // dx/ds
53
54        // forward computation of partials w.r.t. t
55        v[s] = 0.;
56        v[t] = 1.;
57        w    = f.Forward(1, v);
58        ok &= ( w[x] == -1. );   // dx/dt
59
60        // reverse computation of second partials of z
61        CPPAD_TEST_VECTOR<double> r( f.Domain() * 2 );
62        w[x] = 1.;
63        r    = f.Reverse(2, w);
64        ok &= ( r[2 * s + 1] == 0. );  // d^2 x / (ds ds)
65        ok &= ( r[2 * t + 1] == 0. );  // d^2 x / (ds dt)
66         
67        return ok;
68}
69// END PROGRAM
Note: See TracBrowser for help on using the repository browser.