/* ---------------------------------------------------------------------------- f2cad: Convert Fortran to C++ AD Types: Copyright (C) 2005-10 Bradley M. Bell Authors: Bradley M. Bell bradbell at washington dot edu License: GNU Public License Version 2 or higher -----------------------------------------------------------------------------*/ /* $begin daxpy$$spell hpp daxpy bool doublereal Blas incx incf df$$$section daxpy$$index blas, daxpy$$ $index daxpy, blas$$head Prototype$$$include p.omh/daxpy.p.omh$$children% omh/daxpy.f.omh %$$ $head Fortran Source$$cref daxpy.f$$$head Description$$This example uses codei%daxpy.f%$$ to compute $latex $\left( \begin{array}{c} f_0 \\ f_1 \end{array} \right) = 5 \left( \begin{array}{c} x_0 \\ x_1 \end{array} \right) + \left( \begin{array}{c} 3 \\ 4 \end{array} \right)$ $$Using the xref/f2cad_link/$$ routines$code f2cad::Independent$$and code f2cad::Dependent$$, this defines the function $latex $f(x) = \left( \begin{array}{c} 5 x_0 + 3 \\ 5 x_1 + 4 \end{array} \right)$ $$We check that the derivative of this function, calculated using the code f2cad::Partial$$ routine, satisfies$latex $f^{(1)} (x) = \left( \begin{array}{cc} 5 & 0 \\ 0 & 5 \end{array} \right)$ $$codep */ # include test_result daxpy(void) { bool ok = true; // Input values for daxpy doublereal a = 5.; integer n = 2; doublereal x[2]; x[0] = 1.; x[1] = 2.; integer incx = 1; integer m = 2; doublereal f[2]; f[0] = 3.; f[1] = 4.; integer incf = 1; // declare independent variables f2cad::Independent(n, x); // set f = a * x + f f2cad::daxpy_(&n, &a, x, &incx, f, &incf); // declare dependent variables f2cad::Dependent(m, f); double p; p = f2cad::Partial(0, 0); ok &= f2cad::near_equal(p, 5., 1e-10, 1e-10); p = f2cad::Partial(1, 0); ok &= f2cad::near_equal(p, 0., 1e-10, 1e-10); p = f2cad::Partial(0, 1); ok &= f2cad::near_equal(p, 0., 1e-10, 1e-10); p = f2cad::Partial(1, 1); ok &= f2cad::near_equal(p, 5., 1e-10, 1e-10); if( ok ) return test_pass; return test_fail; } /*$$ \$end */