source: trunk/test_more/pow_int.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.7 KB
Line 
1/* $Id: pow_int.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 now just used for validation testing.
15*/
16
17# include <cppad/cppad.hpp>
18
19bool PowInt(void)
20{       bool ok = true;
21
22        using CppAD::pow;
23        using CppAD::exp;
24        using CppAD::log;
25        using namespace CppAD;
26
27
28        // independent variable vector, indices, values, and declaration
29        CPPAD_TEST_VECTOR< AD<double> > U(1);
30        U[0]     = 2.;
31        Independent(U);
32
33        // dependent variable vector and indices
34        CPPAD_TEST_VECTOR< AD<double> > Z(2);
35
36        // dependent variable values
37        Z[0]         = pow(U[0], 5);     // x = u^5
38        Z[1]         = pow(U[0], -5);    // y = u^{-5}
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        /*
46        x_u = 5 * u^4
47        y_u = - 5 * u^{-6}
48        */
49
50        // check function values values
51        double u = Value(U[0]);
52        ok &= NearEqual(Z[0] , exp( log(u) * 5.),              1e-10 , 1e-10);
53        ok &= NearEqual(Z[1] , exp( - log(u) * 5.),            1e-10 , 1e-10);
54
55        // forward computation of partials
56        v[0] = 1.;
57        w = f.Forward(1, v);
58        ok &= NearEqual(w[0] , 5. * exp( log(u) * 4.),         1e-10 , 1e-10);
59        ok &= NearEqual(w[1] , - 5. * exp( - log(u) * 6.),     1e-10 , 1e-10);
60
61        return ok;
62}
Note: See TracBrowser for help on using the repository browser.