/* \$Id: acos.cpp 2506 2012-10-24 19:36:49Z bradbell \$ */ /* -------------------------------------------------------------------------- CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell CppAD is distributed under multiple licenses. This distribution is under the terms of the Eclipse Public License Version 1.0. A copy of this license is included in the COPYING file of this distribution. Please visit http://www.coin-or.org/CppAD/ for information on other licenses. -------------------------------------------------------------------------- */ /* Old Acos examples now used just for valiadation testing */ # include bool Acos(void) { bool ok = true; using CppAD::acos; using namespace CppAD; // independent variable vector CPPAD_TESTVECTOR(AD) U(1); U[0] = .5; Independent(U); // a temporary values AD x = cos(U[0]); // dependent variable vector CPPAD_TESTVECTOR(AD) Z(1); Z[0] = acos(x); // acos( cos(u) ) // create f: U -> Z and vectors used for derivative calculations ADFun f(U, Z); CPPAD_TESTVECTOR(double) v(1); CPPAD_TESTVECTOR(double) w(1); // check value ok &= NearEqual(U[0] , Z[0], 1e-10 , 1e-10); // forward computation of partials w.r.t. u size_t j; size_t p = 5; double jfac = 1.; double value = 1.; v[0] = 1.; for(j = 1; j < p; j++) { jfac *= j; w = f.Forward(j, v); ok &= NearEqual(jfac*w[0], value, 1e-10 , 1e-10); // d^jz/du^j v[0] = 0.; value = 0.; } // reverse computation of partials of Taylor coefficients CPPAD_TESTVECTOR(double) r(p); w[0] = 1.; r = f.Reverse(p, w); jfac = 1.; value = 1.; for(j = 0; j < p; j++) { ok &= NearEqual(jfac*r[j], value, 1e-10 , 1e-10); // d^jz/du^j jfac *= (j + 1); value = 0.; } return ok; }