<?xml version='1.0'?> <?xml-stylesheet type='text/xsl' href='pmathml.xsl'?> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>The AD acos Function: Example and Test</title> <meta name="description" id="description" content="The AD acos Function: Example and Test"/> <meta name="keywords" id="keywords" content=" acos Ad example test "/> <style type='text/css'> body { color : black } body { background-color : white } A:link { color : blue } A:visited { color : purple } A:active { color : purple } </style> <script type='text/javascript' language='JavaScript' src='_acos.cpp_xml.js'> </script> </head> <body> <table><tr> <td> <a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a> </td> <td><a href="std_math_ad.xml" target="_top">Prev</a> </td><td><a href="asin.cpp.xml" target="_top">Next</a> </td><td> <select onchange='choose_across0(this)'> <option>Index-></option> <option>contents</option> <option>reference</option> <option>index</option> <option>search</option> <option>external</option> </select> </td> <td> <select onchange='choose_up0(this)'> <option>Up-></option> <option>CppAD</option> <option>AD</option> <option>ADValued</option> <option>std_math_ad</option> <option>Acos.cpp</option> </select> </td> <td> <select onchange='choose_down3(this)'> <option>AD-></option> <option>Default</option> <option>ad_copy</option> <option>Convert</option> <option>ADValued</option> <option>BoolValued</option> <option>VecAD</option> <option>base_require</option> </select> </td> <td> <select onchange='choose_down2(this)'> <option>ADValued-></option> <option>Arithmetic</option> <option>std_math_ad</option> <option>MathOther</option> <option>CondExp</option> <option>Discrete</option> </select> </td> <td> <select onchange='choose_down1(this)'> <option>std_math_ad-></option> <option>Acos.cpp</option> <option>Asin.cpp</option> <option>Atan.cpp</option> <option>Cos.cpp</option> <option>Cosh.cpp</option> <option>Exp.cpp</option> <option>Log.cpp</option> <option>Log10.cpp</option> <option>Sin.cpp</option> <option>Sinh.cpp</option> <option>Sqrt.cpp</option> <option>Tan.cpp</option> <option>Tanh.cpp</option> </select> </td> <td>Acos.cpp</td> <td>Headings</td> </tr></table><br/> <center><b><big><big>The AD acos Function: Example and Test</big></big></b></center> <code><font color="blue"><pre style='display:inline'> # include <cppad/cppad.hpp> bool Acos(void) { bool ok = true; using CppAD::AD; using CppAD::NearEqual; // domain space vector size_t n = 1; double x0 = 0.5; <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>< <a href="ad.xml" target="_top">AD</a><double> > x(n); x[0] = x0; // declare independent variables and start tape recording CppAD::<a href="independent.xml" target="_top">Independent</a>(x); // a temporary value <a href="ad.xml" target="_top">AD</a><double> cos_of_x0 = CppAD::cos(x[0]); // range space vector size_t m = 1; <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>< <a href="ad.xml" target="_top">AD</a><double> > y(m); y[0] = CppAD::acos(cos_of_x0); // create f: x -> y and stop tape recording CppAD::<a href="funconstruct.xml" target="_top">ADFun</a><double> f(x, y); // check value ok &= <a href="nearequal.xml" target="_top">NearEqual</a>(y[0] , x0, 1e-10 , 1e-10); // forward computation of first partial w.r.t. x[0] <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a><double> dx(n); <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a><double> dy(m); dx[0] = 1.; dy = f.<a href="forward.xml" target="_top">Forward</a>(1, dx); ok &= <a href="nearequal.xml" target="_top">NearEqual</a>(dy[0], 1., 1e-10, 1e-10); // reverse computation of derivative of y[0] <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a><double> w(m); <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a><double> dw(n); w[0] = 1.; dw = f.<a href="reverse.xml" target="_top">Reverse</a>(1, w); ok &= <a href="nearequal.xml" target="_top">NearEqual</a>(dw[0], 1., 1e-10, 1e-10); // use a VecAD<Base>::reference object with acos CppAD::VecAD<double> v(1); <a href="ad.xml" target="_top">AD</a><double> zero(0); v[zero] = cos_of_x0; <a href="ad.xml" target="_top">AD</a><double> result = CppAD::acos(v[zero]); ok &= <a href="nearequal.xml" target="_top">NearEqual</a>(result, x0, 1e-10, 1e-10); return ok; } </pre> </font></code> <hr/>Input File: example/acos.cpp </body> </html>