![]() |
Prev | Next |
int f2cad::dscal_(integer *n, doublereal *da, doublereal *dx, integer *incx);
dscal.f
to compute
\[
\left( \begin{array}{c}
f_0 \\
f_1
\end{array} \right)
=
a
\left( \begin{array}{c}
1 \\
2
\end{array} \right)
\]
Using the f2cad_link
routines
f2cad::Independent
and f2cad::Dependent
,
this defines the function
\[
f(a) =
\left( \begin{array}{c}
a \\
2 a
\end{array} \right)
\]
We check that the derivative of this function,
calculated using the f2cad::Partial
routine, satisfies
\[
f^{(1)} (a)
=
\left( \begin{array}{c}
1 \\
2
\end{array} \right)
\]
# include <f2cad/dscal.hpp>
test_result dscal(void)
{ bool ok = true;
// Input values for dscal
integer n = 1;
doublereal a[1];
a[0] = 5.;
// declare independent variables
f2cad::Independent(n, a);
integer m = 2;
doublereal f[2];
f[0] = 1.;
f[1] = 2.;
integer incf = 1;
// set f = a * f
f2cad::dscal_(&n, a, f, &incf );
// declare dependent variables
f2cad::Dependent(m, f);
double p;
p = f2cad::Partial<doublereal>(0, 0);
ok &= f2cad::near_equal(p, 1., 1e-10, 1e-10);
p = f2cad::Partial<doublereal>(1, 0);
ok &= f2cad::near_equal(p, 2., 1e-10, 1e-10);
if( ok )
return test_pass;
return test_fail;
}