<?xml version='1.0'?> <?xml-stylesheet type='text/xsl' href='pmathml.xsl'?> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>AD Parameter and Variable Functions: Example and Test</title> <meta name="description" id="description" content="AD Parameter and Variable Functions: Example and Test"/> <meta name="keywords" id="keywords" content=" Parameter example Variable 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='_parvar.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="parvar.xml" target="_top">Prev</a> </td><td><a href="equalopseq.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>BoolValued</option> <option>ParVar</option> <option>ParVar.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>BoolValued-></option> <option>Compare</option> <option>NearEqualExt</option> <option>BoolFun</option> <option>ParVar</option> <option>EqualOpSeq</option> </select> </td> <td> <select onchange='choose_down1(this)'> <option>ParVar-></option> <option>ParVar.cpp</option> </select> </td> <td>ParVar.cpp</td> <td>Headings</td> </tr></table><br/> <center><b><big><big>AD Parameter and Variable Functions: Example and Test</big></big></b></center> <code><font color="blue"><pre style='display:inline'> # include <cppad/cppad.hpp> bool ParVar(void) { bool ok = true; using CppAD::AD; using CppAD::VecAD; using CppAD::Parameter; using CppAD::Variable; // declare independent variables and start tape recording size_t n = 1; <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>< <a href="ad.xml" target="_top">AD</a><double> > x(n); x[0] = 0.; ok &= Parameter(x[0]); // x[0] is a paraemter here CppAD::<a href="independent.xml" target="_top">Independent</a>(x); ok &= Variable(x[0]); // now x[0] is a variable // dependent variable vector size_t m = 2; <a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>< <a href="ad.xml" target="_top">AD</a><double> > y(m); y[0] = 2.; ok &= Parameter(y[0]); // y[0] does not depend on x[0] y[1] = abs(x[0]); ok &= Variable(y[1]); // y[1] does depends on x[0] // VecAD objects VecAD<double> z(2); z[0] = 0.; z[1] = 1.; ok &= Parameter(z); // z does not depend on x[0] z[x[0]] = 2.; ok &= Variable(z); // z depends on x[0] // create f: x -> y and stop tape recording CppAD::<a href="funconstruct.xml" target="_top">ADFun</a><double> f(x, y); // check that now all <a href="ad.xml" target="_top">AD</a><double> objects are parameters ok &= Parameter(x[0]); ok &= ! Variable(x[0]); ok &= Parameter(y[0]); ok &= ! Variable(y[0]); ok &= Parameter(y[1]); ok &= ! Variable(y[1]); // check that the VecAD<double> object is a parameter ok &= Parameter(z); return ok; } </pre> </font></code> <hr/>Input File: example/par_var.cpp </body> </html>