Prev Next

ddot

Prototype
doublereal f2cad::ddot_(integer *n, doublereal *dx, integer *incx, doublereal *dy, integer *incy);

Fortran Source
ddot.f

Description
This example uses the routine ddot.f to compute  \[
f_0
=
\left( \begin{array}{cc}
     x_0 & x_1 
\end{array} \right)
\left( \begin{array}{c}
     x_2 \\
     x_3 
\end{array} \right)
\] 
Using the f2cad_link routines f2cad::Independent and f2cad::Dependent, this defines the function  \[
f(x) =  x_0 * x_2 + x_1 * x_3
\] 
We check that the derivative of this function, calculated using the f2cad::Partial routine, satisfies  \[
f^{(1)} (x)
=
\left( \begin{array}{cccc}
     x_2 & x_3 & x_0 & x_1
\end{array} \right)
\] 
 

# include <f2cad/ddot.hpp>

test_result ddot(void)
{	bool ok = true;

	integer n   = 4;
	doublereal x[4];
	x[0]        = 1.;
	x[1]        = 2.;
	x[2]        = 3.;
	x[3]        = 4.;

	// declare independent variables
	f2cad::Independent(n, x);

	// set f = x[0] * x[2] + x[1] * x[3] 
	integer m    = 1;
	doublereal f[1];
	integer incx = 1;
	integer n2   = n / 2;
	f[0]         = f2cad::ddot_ (&n2, x, &incx, x+n2, &incx);

	// declare dependent variables
	f2cad::Dependent(m, f);

	double p;
	p   = f2cad::Partial<doublereal>(0, 0);
	ok &= f2cad::near_equal(p, f2cad::Value(x[2]), 1e-10, 1e-10);

	p   = f2cad::Partial<doublereal>(0, 1);
	ok &= f2cad::near_equal(p, f2cad::Value(x[3]), 1e-10, 1e-10);

	p   = f2cad::Partial<doublereal>(0, 2);
	ok &= f2cad::near_equal(p, f2cad::Value(x[0]), 1e-10, 1e-10);

	p   = f2cad::Partial<doublereal>(0, 3);
	ok &= f2cad::near_equal(p, f2cad::Value(x[1]), 1e-10, 1e-10);

	if( ok )
		return test_pass;
	return test_fail;
}

Input File: example/ddot.cpp