# source:trunk/test_more/poly.cpp@2506

Last change on this file since 2506 was 2506, checked in by bradbell, 8 years ago

Change Licenses: CPL-1.0 -> EPL-1.0, GPL-2.0->GPL-3.0

• Property svn:keywords set to `Id`
File size: 2.1 KB
Line
1/* \$Id: poly.cpp 2506 2012-10-24 19:36:49Z bradbell \$ */
2/* --------------------------------------------------------------------------
4
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.
11-------------------------------------------------------------------------- */
12
13/*
14// Old GetStarted example now used just for validation testing
15*/
16// BEGIN C++
17
20
21bool Poly(void)
22{       bool ok = true;
23
26
27        // degree of the polynomial that we will differentiate
28        size_t deg = 4;
29
30        // vector that will hold polynomial coefficients for p(z)
32        CPPAD_TESTVECTOR(double)       a(deg + 1);  //    double  elements
33
34        // set the polynomial coefficients
35        A = 1.;
36        size_t k;
37        for(k = 1; k <= deg; k++)
38                A[k] = a[k] = 1.;
39
40        // independent variables
42        Z     = 3.;                        // value of independent variable
43        Independent(Z);                       // declare independent variable
44
45        // dependent variables
47        P     = Poly(0, A, Z);    // value of polynomial at Z
48
49        // define f : Z -> P as a function mapping independent to dependent
51
52        // compute derivative of polynomial
53        CPPAD_TESTVECTOR(double) z(1);  // vector length f.Domain()
54        CPPAD_TESTVECTOR(double) J(1);  // vector length f.Range * f.Domain()
55        z = 3.;                 // point at which to compute derivative
56        J    = f.Jacobian(z);      // value of derivative
57
58        // compare with derivative as computed by Poly
59        ok  &= (Poly(1, a, z) == J);
60
61        return ok;
62}
63
64// END C++
Note: See TracBrowser for help on using the repository browser.