![]() |
Prev | Next | start_fadbad.cpp |
int f2cad::dscal_(integer *n, doublereal *da, doublereal *dx, integer *incx);
libf2cadFadbad.a
library routine dscal
to
compute the function
\[
f(a) =
a
\left( \begin{array}{c}
1 \\
2
\end{array} \right)
\]
We check that the derivative of this function,
calculated using the Fadbad, satisfies
\[
f^{(1)} (a)
=
\left( \begin{array}{c}
1 \\
2
\end{array} \right)
\]
// standard input output library
# include <iostream>
// f2cad set up for F<double>
# define F2CAD_USE_FADBAD
// prototype for dscal
# include <f2cad/dscal.hpp>
int main(void)
{
// independent variables
doublereal a[1]; // vector of independent variables
a[0] = 5.; // value of independent variables
a[0].diff(0, 1); // declare independent variables
// create data structure expected by dscal
integer m = 2;
doublereal f[2];
f[0] = 1.;
f[1] = 2.;
integer incf = 1;
// set f = a * f
f2cad::dscal_(&m, a, f, &incf );
// print results
std::cout << "f(a) = a * (1, 2)^T" << std::endl;
std::cout << "f'(a) = ("
<< f[0].d(0)
<< ", "
<< f[1].d(0)
<< ")^T"
<< std::endl;
// return value not significant
if( f[0].d(0) != 1. || f[1].d(0) != 2. )
return 1; // error
return 0; // no error
}