source: trunk/test_more/log_10.cpp @ 1559

Last change on this file since 1559 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: log_10.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 used just for validation testing.
15*/
16# include <cppad/cppad.hpp>
17
18bool Log10(void)
19{       bool ok = true;
20
21        using CppAD::log10;
22        using CppAD::log;
23        using namespace CppAD;
24
25        // independent variable vector, indices, values, and declaration
26        CPPAD_TEST_VECTOR< AD<double> > U(1);
27        size_t s = 0;
28        U[s]     = 10.;
29        Independent(U);
30
31        // dependent variable vector, indices, and values
32        CPPAD_TEST_VECTOR< AD<double> > Z(2);
33        size_t x = 0;
34        size_t y = 1;
35        Z[x]     = log10(U[s]);
36        Z[y]     = log10(Z[x]);
37
38        // define f : U -> Z and vectors for derivative calculations
39        ADFun<double> f(U, Z);
40        CPPAD_TEST_VECTOR<double> v( f.Domain() );
41        CPPAD_TEST_VECTOR<double> w( f.Range() );
42
43        // check values
44        ok &= NearEqual(Z[x] , 1.,  1e-10 , 1e-10);
45        ok &= NearEqual(Z[y] , 0.,  1e-10 , 1e-10);
46
47        // forward computation of partials w.r.t. s
48        double l10 = log(10.);
49        v[s] = 1.;
50        w    = f.Forward(1, v);
51        ok &= NearEqual(w[x], 1./(U[s]*l10)         , 1e-10 , 1e-10); // dx/ds
52        ok &= NearEqual(w[y], 1./(U[s]*Z[x]*l10*l10), 1e-10 , 1e-10); // dy/ds
53
54        // reverse computation of partials of y
55        w[x] = 0.;
56        w[y] = 1.;
57        v    = f.Reverse(1,w);
58        ok &= NearEqual(v[s], 1./(U[s]*Z[x]*l10*l10), 1e-10 , 1e-10); // dy/ds
59
60        return ok;
61}
Note: See TracBrowser for help on using the repository browser.