# source:trunk/example/acos.cpp@2506

Last change on this file since 2506 was 2506, checked in by bradbell, 7 years ago

Change Licenses: CPL-1.0 -> EPL-1.0, GPL-2.0->GPL-3.0

• Property svn:keywords set to `Id`
File size: 2.0 KB
Line
1/* \$Id: acos.cpp 2506 2012-10-24 19:36:49Z bradbell \$ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
4
6the terms of the
7                    Eclipse Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
11-------------------------------------------------------------------------- */
12
13/*
14\$begin Acos.cpp\$\$
15\$spell
16        cos
17        acos
18\$\$
19
20\$section The AD acos Function: Example and Test\$\$
21
22\$index acos, AD example\$\$
23\$index example, AD acos\$\$
24\$index test, AD acos\$\$
25
26\$code
27\$verbatim%example/acos.cpp%0%// BEGIN C++%// END C++%1%\$\$
28\$\$
29
30\$end
31*/
32// BEGIN C++
33
35
36bool Acos(void)
37{       bool ok = true;
38
41
42        // domain space vector
43        size_t n  = 1;
44        double x0 = 0.5;
46        x[0]      = x0;
47
48        // declare independent variables and start tape recording
50
51        // a temporary value
53
54        // range space vector
55        size_t m = 1;
57        y[0] = CppAD::acos(cos_of_x0);
58
59        // create f: x -> y and stop tape recording
61
62        // check value
63        ok &= NearEqual(y[0] , x0,  1e-10 , 1e-10);
64
65        // forward computation of first partial w.r.t. x[0]
68        dx[0] = 1.;
69        dy    = f.Forward(1, dx);
70        ok   &= NearEqual(dy[0], 1., 1e-10, 1e-10);
71
72        // reverse computation of derivative of y[0]
75        w[0]  = 1.;
76        dw    = f.Reverse(1, w);
77        ok   &= NearEqual(dw[0], 1., 1e-10, 1e-10);
78
79        // use a VecAD<Base>::reference object with acos