/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/rev_one.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_REV_ONE_INCLUDED
00002 # define CPPAD_REV_ONE_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-06 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 
00015 /*
00016 $begin RevOne$$
00017 $spell
00018         dw
00019         Taylor
00020         const
00021 $$
00022 
00023 
00024 $index derivative, first order driver$$
00025 $index first, order derivative driver$$
00026 $index driver, first order derivative$$
00027 
00028 $index easy, derivative$$
00029 $index driver, easy derivative$$
00030 $index derivative, easy$$
00031 
00032 $section First Order Derivative: Driver Routine$$
00033 
00034 $head Syntax$$
00035 $syntax%%dw% = %f%.RevOne(%x%, %i%)%$$
00036 
00037 
00038 $head Purpose$$
00039 We use $latex F : B^n \rightarrow B^m$$ to denote the
00040 $xref/glossary/AD Function/AD function/$$ corresponding to $italic f$$.
00041 The syntax above sets $italic dw$$ to the
00042 derivative of $latex F_i$$ with respect to $latex x$$; i.e.,
00043 $latex \[
00044 dw =
00045 F_i^{(1)} (x) 
00046 = \left[ 
00047         \D{ F_i }{ x_0 } (x) , \cdots , \D{ F_i }{ x_{n-1} } (x) 
00048 \right]
00049 \] $$
00050 
00051 $head f$$
00052 The object $italic f$$ has prototype
00053 $syntax%
00054         ADFun<%Base%> %f%
00055 %$$
00056 Note that the $xref/ADFun/$$ object $italic f$$ is not $code const$$
00057 (see $xref/RevOne/RevOne Uses Forward/RevOne Uses Forward/$$ below).
00058 
00059 $head x$$
00060 The argument $italic x$$ has prototype
00061 $syntax%
00062         const %Vector% &%x%
00063 %$$
00064 (see $xref/RevOne/Vector/Vector/$$ below)
00065 and its size 
00066 must be equal to $italic n$$, the dimension of the
00067 $xref/SeqProperty/Domain/domain/$$ space for $italic f$$.
00068 It specifies
00069 that point at which to evaluate the derivative.
00070 
00071 $head i$$
00072 The index $italic i$$ has prototype
00073 $syntax%
00074         size_t %i%
00075 %$$
00076 and is less than $latex m$$, the dimension of the
00077 $xref/SeqProperty/Range/range/$$ space for $italic f$$.
00078 It specifies the
00079 component of $latex F$$ that we are computing the derivative of.
00080 
00081 $head dw$$
00082 The result $italic dw$$ has prototype
00083 $syntax%
00084         %Vector% %dw%
00085 %$$
00086 (see $xref/RevOne/Vector/Vector/$$ below)
00087 and its size is $italic n$$, the dimension of the
00088 $xref/SeqProperty/Domain/domain/$$ space for $italic f$$.
00089 The value of $italic dw$$ is the derivative of $latex F_i$$ 
00090 evaluated at $italic x$$; i.e.,
00091 for $latex j = 0 , \ldots , n - 1 $$ 
00092 $latex \[.
00093         dw[ j ] = \D{ F_i }{ x_j } ( x )
00094 \] $$
00095 
00096 $head Vector$$
00097 The type $italic Vector$$ must be a $xref/SimpleVector/$$ class with
00098 $xref/SimpleVector/Elements of Specified Type/elements of type/$$
00099 $italic Base$$.
00100 The routine $xref/CheckSimpleVector/$$ will generate an error message
00101 if this is not the case.
00102 
00103 $head RevOne Uses Forward$$
00104 After each call to $xref/Forward/$$,
00105 the object $italic f$$ contains the corresponding 
00106 $xref/glossary/Taylor Coefficient/Taylor coefficients/$$.
00107 After $code RevOne$$,
00108 the previous calls to $xref/Forward/$$ are undefined.
00109 
00110 $head Example$$
00111 $children%
00112         example/rev_one.cpp
00113 %$$
00114 The routine 
00115 $xref/RevOne.cpp//RevOne/$$ is both an example and test.
00116 It returns $code true$$, if it succeeds and $code false$$ otherwise.
00117 
00118 $end
00119 -----------------------------------------------------------------------------
00120 */
00121 
00122 //  BEGIN CppAD namespace
00123 namespace CppAD {
00124 
00125 template <typename Base>
00126 template <typename Vector>
00127 Vector ADFun<Base>::RevOne(const Vector  &x, size_t i)
00128 {       size_t i1;
00129 
00130         size_t n = Domain();
00131         size_t m = Range();
00132 
00133         // check Vector is Simple Vector class with Base type elements
00134         CheckSimpleVector<Base, Vector>();
00135 
00136         CPPAD_ASSERT_KNOWN(
00137                 x.size() == n,
00138                 "RevOne: Length of x not equal domain dimension for f"
00139         ); 
00140         CPPAD_ASSERT_KNOWN(
00141                 i < m,
00142                 "RevOne: the index i is not less than range dimension for f"
00143         );
00144 
00145         // point at which we are evaluating the derivative
00146         Forward(0, x);
00147 
00148         // component which are are taking the derivative of
00149         Vector w(m);
00150         for(i1 = 0; i1 < m; i1++)
00151                 w[i1] = 0.;
00152         w[i] = Base(1);
00153 
00154         // dimension the return value
00155         Vector dw(n);
00156 
00157         // compute the return value
00158         dw = Reverse(1, w);
00159 
00160         return dw;
00161 }
00162 
00163 } // END CppAD namespace
00164 
00165 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7