ADMB Documentation  11.1.2258
 All Classes Files Functions Variables Typedefs Friends Defines
df12fun.h
Go to the documentation of this file.
00001 /*
00002  * $Id: df12fun.h 1933 2014-04-25 18:25:29Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 #if !defined(__DF12FUN__)
00046 #  define __DF12FUN__
00047 #include <fvar.hpp>
00048 //class df1b2variable;
00049 
00054   class df1_two_variable
00055   {
00056     double v[3];
00057   public:
00058     static prevariable * ind_var[];
00059     static int num_ind_var;
00060     double * get_u(void) const {return (double*) (&(v[0]));}
00061     double * get_u_x(void)const {return (double*) (&(v[1]));}
00062     double * get_u_y(void)const {return (double*) (&(v[2]));}
00063     df1_two_variable& operator = (const df1_two_variable& v);
00064     df1_two_variable& operator = (double v);
00065     df1_two_variable& operator += (const df1_two_variable& v);
00066     df1_two_variable& operator *= (double v);
00067     df1_two_variable& operator *= (const df1_two_variable& v);
00068     df1_two_variable& operator += (double v);
00069     df1_two_variable& operator -= (const df1_two_variable& v);
00070     df1_two_variable& operator -= (double v);
00071     df1_two_variable& operator /= (const df1_two_variable& v);
00072     df1_two_variable(void);
00073     df1_two_variable(const df1_two_variable& );
00074   };
00075 
00076   inline double value(const df1_two_variable& x) { return double(*x.get_u()); }
00077 
00082   class init_df1_two_variable : public df1_two_variable
00083   {
00084   public:
00085     ~init_df1_two_variable();
00086     void deallocate(void);
00087     init_df1_two_variable(const prevariable& );
00088     init_df1_two_variable(double );
00089   };
00090 
00095   class df1_two_vector
00096   {
00097     int index_min;
00098     int index_max;
00099     vector_shapex * shape;
00100     df1_two_variable * v;
00101   public:
00102     int indexmin(void) const { return int(index_min); }
00103     int indexmax(void) const { return int(index_max); }
00104     df1_two_vector(int min,int max);
00105     df1_two_vector(void);
00106     void allocate(void);
00107     void allocate(int min,int max);
00108     df1_two_variable& operator () (int i) const
00109     {
00110       return (df1_two_variable&) (*(v+i));
00111     }
00112     df1_two_variable& operator [] (int i) const
00113     {
00114       return (df1_two_variable&) (*(v+i));
00115     }
00116     void initialize(void);
00117     void deallocate(void);
00118     ~df1_two_vector();
00119     df1_two_vector(const df1_two_vector& m2);
00120   };
00121 
00122 
00123 
00124  dvector value(const df1_two_vector& v);
00125  dvector first_derivatives(const df1_two_vector& v);
00126 
00131   class df1_two_matrix
00132   {
00133     int index_min;
00134     int index_max;
00135     mat_shapex * shape;
00136     df1_two_vector * v;
00137   public:
00138     int indexmin(void) const { return int(index_min); }
00139     int indexmax(void) const { return int(index_max); }
00140     df1_two_matrix(int rmin,int rmax,int cmin,int cmax);
00141     df1_two_vector& operator () (int i) const
00142     {
00143       return (df1_two_vector&) *(v+i);
00144     }
00145     df1_two_vector& operator [] (int i) const
00146     {
00147       return (df1_two_vector&) *(v+i);
00148     }
00149     df1_two_variable& operator () (int i,int j) const
00150     {
00151       return (df1_two_variable&) (*(v+i))(j);
00152     }
00153     void initialize(void);
00154 //df1_two_variable& operator()(int i,int j) const { return *((v+i)->(v+j)); }
00155     void deallocate(void);
00156     ~df1_two_matrix();
00157     df1_two_matrix(const df1_two_matrix& m2);
00158   };
00159 
00160  dmatrix value(const df1_two_matrix& v);
00161 
00162  dmatrix first_derivatives(const df1_two_matrix& v);
00163  dmatrix second_derivatives(const df1_two_matrix& v);
00164  dmatrix third_derivatives(const df1_two_matrix& v);
00165 
00166 /*
00167   df1_two_variable operator F(const df1_two_variable& x)
00168   {
00169     df1_two_variable z;
00170 
00171     *z.get_u() = ::F(*x.get_u());
00172 
00173     *z.get_udot() = ::D1F(*x.get_u())* *x.get_udot();
00174 
00175     *z.get_udot2() = ::D2F(*x.get_u())* square(*x.get_udot())
00176                    + ::D1F(*x.get_u())* *x.get_udot2();
00177 
00178     *z.get_udot3() = ::D3F(*x.get_u()) * cube(*x.get_udot())
00179                    + 3.0 * ::D2F(*x.get_u()) * *x.get_udot() * *x.get_udot2()
00180                    + ::D1F(*x.get_u()) * *x.get_udot3();
00181     return z;
00182   }
00183 
00184 */
00185 
00186   df1_two_variable sin(const df1_two_variable& x);
00187   df1_two_variable sqrt(const df1_two_variable& x);
00188   df1_two_variable fabs(const df1_two_variable& x);
00189   df1_two_variable atan(const df1_two_variable& x);
00190   df1_two_variable cos(const df1_two_variable& x);
00191   df1_two_variable tan(const df1_two_variable& x);
00192   df1_two_variable log(const df1_two_variable& x);
00193   df1_two_variable square(const df1_two_variable& x);
00194   df1_two_variable cube(const df1_two_variable& x);
00195   df1_two_variable pow(const df1_two_variable& x,
00196     const df1_two_variable& y);
00197   df1_two_variable pow(double x,const df1_two_variable& y);
00198 
00199   df1_two_variable sqrt(const df1_two_variable& x);
00200   df1_two_variable exp(const df1_two_variable& x);
00201   df1_two_variable inv(const df1_two_variable& x);
00202   df1_two_variable operator * (const df1_two_variable& x,
00203     const df1_two_variable& y);
00204   df1_two_variable operator * (double x,
00205     const df1_two_variable& y);
00206   df1_two_variable operator * (const df1_two_variable& x,
00207     double y);
00208   df1_two_variable operator / (const df1_two_variable& x,
00209     const df1_two_variable& y);
00210 
00211   df1_two_variable operator / (const double x,const df1_two_variable& y);
00212 
00213   df1_two_variable operator / (const df1_two_variable& x,
00214     const double y);
00215 
00216   df1_two_variable operator + (const double x,
00217     const df1_two_variable& y);
00218 
00219   df1_two_variable operator + (const df1_two_variable& x,
00220     const double y);
00221 
00222   df1_two_variable operator + (const df1_two_variable& x,
00223     const df1_two_variable& y);
00224   df1_two_variable operator - (double x,const df1_two_variable& y);
00225   df1_two_variable operator - (const df1_two_variable& x,double y);
00226 
00227   df1_two_variable operator - (const df1_two_variable& x,
00228     const df1_two_variable& y);
00229   df1_two_variable operator - (const df1_two_variable& x,
00230     const df1_two_variable& y);
00231   df1_two_variable operator / (const df1_two_variable& x,
00232     const df1_two_variable& y);
00233   df1_two_variable operator * (const df1_two_variable& x,
00234     const df1_two_variable& y);
00235 
00236   df1_two_variable operator - (const df1_two_variable& v);
00237   df1_two_matrix choleski_decomp(const df1_two_matrix& MM);
00238 
00239   df1_two_variable cumd_gamma(const df1_two_variable& x,
00240     const df1_two_variable& a);
00241 
00242   df1_two_variable gammln(const df1_two_variable& xx);
00243 #endif  // __DF12FUN__