source: trunk/test_more/asin.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.8 KB
Line 
1/* $Id: asin.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 only used for validation testing.
15*/
16
17# include <cppad/cppad.hpp>
18
19bool Asin(void)
20{       bool ok = true;
21
22        using CppAD::asin;
23        using namespace CppAD;
24
25        // independent variable vector
26        CPPAD_TEST_VECTOR< AD<double> > U(1);
27        U[0]     = .5;
28        Independent(U);
29
30        // a temporary values
31        AD<double> x = sin(U[0]); 
32
33        // dependent variable vector
34        CPPAD_TEST_VECTOR< AD<double> > Z(1);
35        Z[0] = asin(x); // asin( sin(u) )
36
37        // create f: U -> Z and vectors used for derivative calculations
38        ADFun<double> f(U, Z); 
39        CPPAD_TEST_VECTOR<double> v(1);
40        CPPAD_TEST_VECTOR<double> w(1);
41
42        // check value
43        ok &= NearEqual(U[0] , Z[0],  1e-10 , 1e-10);
44
45        // forward computation of partials w.r.t. u
46        size_t j;
47        size_t p     = 5;
48        double jfac  = 1.;
49        double value = 1.;
50        v[0]         = 1.;
51        for(j = 1; j < p; j++)
52        {       jfac *= j;
53                w     = f.Forward(j, v);       
54                ok &= NearEqual(jfac*w[0], value, 1e-10 , 1e-10); // d^jz/du^j
55                v[0]  = 0.;
56                value = 0.;
57        }
58
59        // reverse computation of partials of Taylor coefficients
60        CPPAD_TEST_VECTOR<double> r(p); 
61        w[0]  = 1.;
62        r     = f.Reverse(p, w);
63        jfac  = 1.;
64        value = 1.;
65        for(j = 0; j < p; j++)
66        {       ok &= NearEqual(jfac*r[j], value, 1e-10 , 1e-10); // d^jz/du^j
67                jfac *= (j + 1);
68                value = 0.;
69        }
70
71        return ok;
72}
Note: See TracBrowser for help on using the repository browser.