source: trunk/test_more/atanh.cpp @ 3741

Last change on this file since 3741 was 3682, checked in by bradbell, 5 years ago

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: c85ed888ce93510f0df134d9fec6b7e185552f41
end hash code: febe930d34888cf37df862a1bf118229b9bf37a5

commit febe930d34888cf37df862a1bf118229b9bf37a5
Author: Brad Bell <bradbell@…>
Date: Fri May 8 14:21:47 2015 -0700

  1. Automatically generated changes for deprecated auto-tools install.
  2. Fix bug in acosh_op multiple direction forward mode.


configure.ac: Add new symbols for acosh and atanh detection (this install never detects them).
acosh_op.hpp: fix bug in multiple direction forward mode.
whats_new_15.omh: mention bug fix.
forward_dir.cpp: test asinh, acosh, and atanh.

commit 5d007c969a1e8bb0f983629f8134022a47ff2d75
Author: Brad Bell <bradbell@…>
Date: Fri May 8 12:27:18 2015 -0700

Remove trialing white space.

commit d88357106a95ee156ecf2101334dc51b22162950
Author: Brad Bell <bradbell@…>
Date: Fri May 8 12:26:58 2015 -0700

Add atanh operator.

commit 03890672ea394862373e4b1aa19a79cf04a71e73
Author: Brad Bell <bradbell@…>
Date: Fri May 8 11:57:45 2015 -0700

Change order to erf asinh acosh.

commit 9657e6dae7b5ef30ea1ea79d344f655e4db4498e
Author: Brad Bell <bradbell@…>
Date: Fri May 8 05:56:33 2015 -0700

Remove trialing white space.

commit cca1d8b8f344582f4c27c3c9c16745625e7e395e
Author: Brad Bell <bradbell@…>
Date: Fri May 8 05:56:06 2015 -0700

Change Atan -> atan.

commit ffa1894b1f97ca342aa84b65b171baad03568f58
Author: Brad Bell <bradbell@…>
Date: Fri May 8 05:37:49 2015 -0700

  1. Extend atan to include atanh.
  2. Remove index commands for words in headings.
  3. Change AtanForward? -> atan_forward.
  4. Remove trailing white space.


acos_forward.omh: add heading as in tan_forward.
asin_forward.omh: add heading as in tan_forward.
atan_forward.omh: change AtanForward? -> atan_forward.

File size: 2.0 KB
Line 
1/* $Id$ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
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.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12
13# include <cppad/cppad.hpp>
14
15bool atanh(void)
16{       bool ok = true;
17
18        using CppAD::AD;
19        using CppAD::NearEqual;
20
21        // 10 times machine epsilon
22        double eps = 10. * std::numeric_limits<double>::epsilon();
23
24        // domain space vector
25        size_t n  = 1;
26        double x0 = 0.5;
27        CPPAD_TESTVECTOR(AD<double>) ax(n);
28        ax[0]     = x0;
29
30        // declare independent variables and start tape recording
31        CppAD::Independent(ax);
32
33        // a temporary value
34        AD<double> tanh_of_x0 = CppAD::tanh(ax[0]);
35
36        // range space vector
37        size_t m = 1;
38        CPPAD_TESTVECTOR(AD<double>) ay(m);
39        ay[0] = CppAD::atanh(tanh_of_x0);
40
41        // create f: x -> y and stop tape recording
42        CppAD::ADFun<double> f(ax, ay);
43
44        // check value
45        ok &= NearEqual(ay[0] , x0,  eps, eps);
46
47        // forward computation of first partial w.r.t. x[0]
48        CPPAD_TESTVECTOR(double) dx(n);
49        CPPAD_TESTVECTOR(double) dy(m);
50        dx[0] = 1.;
51        dy    = f.Forward(1, dx);
52        ok   &= NearEqual(dy[0], 1., eps, eps);
53
54        // forward computation of higher order partials w.r.t. x[0]
55        size_t n_order = 5;
56        for(size_t order = 2; order < n_order; order++)
57        {       dx[0] = 0.;
58                dy    = f.Forward(order, dx);
59                ok   &= NearEqual(dy[0], 0., eps, eps);
60        }
61        // reverse computation of derivatives
62        CPPAD_TESTVECTOR(double)  w(m);
63        CPPAD_TESTVECTOR(double) dw(n_order * n);
64        w[0]  = 1.;
65        dw    = f.Reverse(n_order, w);
66        ok   &= NearEqual(dw[0], 1., eps, eps);
67        for(size_t order = 1; order < n_order; order++)
68                ok   &= NearEqual(dw[order * n + 0], 0., eps, eps);
69
70        return ok;
71}
72
73// END C++
Note: See TracBrowser for help on using the repository browser.