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

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

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