source: trunk/test_more/value.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.5 KB
Line 
1/* $Id: value.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 Value example now used just for valiadation testing
15*/
16// BEGIN PROGRAM
17
18# include <cppad/cppad.hpp>
19
20bool Value(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        // cannot call Value after Independent (tape is recording)
34
35        // dependent variable vector and indices
36        CPPAD_TEST_VECTOR< AD<double> > Z(1);
37        size_t x = 0;
38
39        // dependent variable values
40        Z[x] = - U[t];
41
42        // create f: U -> Z and vectors used for derivative calculations
43        ADFun<double> f(U, Z);
44        CPPAD_TEST_VECTOR<double> v( f.Domain() );
45        CPPAD_TEST_VECTOR<double> w( f.Range() );
46
47        // can call Value after ADFun constructor (tape is no longer recording)
48
49        // check value of s
50        double sValue = Value(U[s]);
51        ok &= ( sValue == 3. );
52
53        // check value of x
54        double xValue = Value(Z[x]);
55        ok &= ( xValue == -4. );
56
57        return ok;
58}
59// END PROGRAM
Note: See TracBrowser for help on using the repository browser.