# source:trunk/test_more/acos.cpp@3520

Last change on this file since 3520 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: 1.8 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/*
14Old Acos examples now used just for valiadation testing
15*/
17
18bool Acos(void)
19{       bool ok = true;
20
22        using namespace CppAD;
23
24        // independent variable vector
26        U[0]     = .5;
27        Independent(U);
28
29        // a temporary values
30        AD<double> x = cos(U[0]);
31
32        // dependent variable vector
34        Z[0] = acos(x); // acos( cos(u) )
35
36        // create f: U -> Z and vectors used for derivative calculations
37        ADFun<double> f(U, Z);
40
41        // check value
42        ok &= NearEqual(U[0] , Z[0],  1e-10 , 1e-10);
43
44        // forward computation of partials w.r.t. u
45        size_t j;
46        size_t p     = 5;
47        double jfac  = 1.;
48        double value = 1.;
49        v[0]         = 1.;
50        for(j = 1; j < p; j++)
51        {       jfac *= j;
52                w     = f.Forward(j, v);
53                ok &= NearEqual(jfac*w[0], value, 1e-10 , 1e-10); // d^jz/du^j
54                v[0]  = 0.;
55                value = 0.;
56        }
57
58        // reverse computation of partials of Taylor coefficients