<?xml version='1.0'?> <?xml-stylesheet type='text/xsl' href='pmathml.xsl'?> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>Convert From AD to its Base Type: Example and Test</title> <meta name="description" id="description" content="Convert From AD to its Base Type: Example and Test"/> <meta name="keywords" id="keywords" content=" Value example test record "/> <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='_value.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="value.xml" target="_top">Prev</a> </td><td><a href="integer.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>Convert</option> <option>Value</option> <option>Value.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>Convert-></option> <option>Value</option> <option>Integer</option> <option>Output</option> <option>PrintFor</option> <option>Var2Par</option> </select> </td> <td> <select onchange='choose_down1(this)'> <option>Value-></option> <option>Value.cpp</option> </select> </td> <td>Value.cpp</td> <td>Headings</td> </tr></table><br/> <center><b><big><big>Convert From AD to its Base Type: Example and Test</big></big></b></center> <code><font color="blue"><pre style='display:inline'> # include <cppad/cppad.hpp> bool Value(void) { bool ok = true; using CppAD::AD; using CppAD::Value; // domain space vector size_t n = 2; <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>< <a href="ad.xml" target="_top">AD</a><double> > x(n); x[0] = 3.; x[1] = 4.; // check value before recording ok &= (Value(x[0]) == 3.); ok &= (Value(x[1]) == 4.); // declare independent variables and start tape recording CppAD::<a href="independent.xml" target="_top">Independent</a>(x); // 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] = - x[1]; // cannot call Value(x[j]) or Value(y[0]) here (currently variables) <a href="ad.xml" target="_top">AD</a><double> p = 5.; // p is a parameter (does not depend on x) ok &= (Value(p) == 5.); // create f: x -> y and stop tape recording CppAD::<a href="funconstruct.xml" target="_top">ADFun</a><double> f(x, y); // can call Value(x[j]) or Value(y[0]) here (currently parameters) ok &= (Value(x[0]) == 3.); ok &= (Value(x[1]) == 4.); ok &= (Value(y[0]) == -4.); return ok; }</pre> </font></code> <hr/>Input File: example/value.cpp </body> </html>