ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
df11fun.h
Go to the documentation of this file.
00001 /*
00002  * $Id$
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  */
00041 
00042 #if !defined(__DF11FUN__)
00043 #  define __DF11FUN__
00044 #include <fvar.hpp>
00045 //class df1b2variable;
00046 
00047   class df1_one_variable
00048   {
00049     double v[2];
00050   public:
00051     static prevariable * ind_var[];
00052     static int num_ind_var;
00053     double * get_u(void) const {return (double*) (&(v[0]));}
00054     double * get_u_x(void)const {return (double*) (&(v[1]));}
00055     double * get_udot(void)const {return (double*) (&(v[1]));}
00056     df1_one_variable& operator = (const df1_one_variable& v);
00057     df1_one_variable& operator = (double v);
00058     df1_one_variable& operator += (const df1_one_variable& v);
00059     df1_one_variable& operator *= (const df1_one_variable& v);
00060     df1_one_variable& operator += (double v);
00061     df1_one_variable& operator -= (const df1_one_variable& v);
00062     df1_one_variable& operator -= (double v);
00063     df1_one_variable& operator /= (const df1_one_variable& v);
00064     df1_one_variable(void);
00065     df1_one_variable(const df1_one_variable& );
00066   };
00067 
00068   inline  double value(const df1_one_variable& x) { return double(*x.get_u()); }
00069 
00070   class init_df1_one_variable : public df1_one_variable
00071   {
00072   public:
00073     ~init_df1_one_variable();
00074     void deallocate(void);
00075     init_df1_one_variable(const prevariable& );
00076     init_df1_one_variable(double );
00077   };
00078 
00079 
00080 
00081   class df1_one_vector
00082   {
00083     int index_min;
00084     int index_max;
00085     vector_shapex * shape;
00086     df1_one_variable * v;
00087   public:
00088     int indexmin(void) const { return int(index_min); }
00089     int indexmax(void) const { return int(index_max); }
00090     df1_one_vector(int min,int max);
00091     df1_one_vector(void);
00092     void allocate(void);
00093     void allocate(int min,int max);
00094     df1_one_variable& operator () (int i) const
00095     {
00096       return (df1_one_variable&) (*(v+i));
00097     }
00098     df1_one_variable& operator [] (int i) const
00099     {
00100       return (df1_one_variable&) (*(v+i));
00101     }
00102     void initialize(void);
00103     void deallocate(void);
00104     ~df1_one_vector();
00105     df1_one_vector(const df1_one_vector& m2);
00106   };
00107 
00108 
00109 
00110  dvector value(const df1_one_vector& v);
00111  dvector first_derivatives(const df1_one_vector& v);
00112 
00113   class df1_one_matrix
00114   {
00115     int index_min;
00116     int index_max;
00117     mat_shapex * shape;
00118     df1_one_vector * v;
00119   public:
00120     int indexmin(void) const { return int(index_min); }
00121     int indexmax(void) const { return int(index_max); }
00122     df1_one_matrix(int rmin,int rmax,int cmin,int cmax);
00123     df1_one_vector& operator () (int i) const
00124     {
00125       return (df1_one_vector&) *(v+i);
00126     }
00127     df1_one_vector& operator [] (int i) const
00128     {
00129       return (df1_one_vector&) *(v+i);
00130     }
00131     df1_one_variable& operator () (int i,int j) const
00132     {
00133       return (df1_one_variable&) (*(v+i))(j);
00134     }
00135     void initialize(void);
00136 //df1_one_variable& operator()(int i,int j) const { return *((v+i)->(v+j)); }
00137     void deallocate(void);
00138     ~df1_one_matrix();
00139     df1_one_matrix(const df1_one_matrix& m2);
00140   };
00141 
00142  dmatrix value(const df1_one_matrix& v);
00143 
00144  dmatrix first_derivatives(const df1_one_matrix& v);
00145  dmatrix second_derivatives(const df1_one_matrix& v);
00146  dmatrix third_derivatives(const df1_one_matrix& v);
00147 
00148 
00149   df1_one_variable sin(const df1_one_variable& x);
00150   df1_one_variable sqrt(const df1_one_variable& x);
00151   df1_one_variable atan(const df1_one_variable& x);
00152   df1_one_variable cos(const df1_one_variable& x);
00153   df1_one_variable tan(const df1_one_variable& x);
00154   df1_one_variable log(const df1_one_variable& x);
00155   df1_one_variable square(const df1_one_variable& x);
00156   df1_one_variable cube(const df1_one_variable& x);
00157   df1_one_variable pow(const df1_one_variable& x,
00158     const df1_one_variable& y);
00159 
00160   df1_one_variable sqrt(const df1_one_variable& x);
00161   df1_one_variable exp(const df1_one_variable& x);
00162   df1_one_variable inv(const df1_one_variable& x);
00163   df1_one_variable operator * (const df1_one_variable& x,
00164     const df1_one_variable& y);
00165   df1_one_variable operator * (double x,
00166     const df1_one_variable& y);
00167   df1_one_variable operator * (const df1_one_variable& x,
00168     double y);
00169   df1_one_variable operator / (const df1_one_variable& x,
00170     const df1_one_variable& y);
00171 
00172   df1_one_variable operator / (const double x,const df1_one_variable& y);
00173 
00174   df1_one_variable operator / (const df1_one_variable& x,
00175     const double y);
00176 
00177   df1_one_variable operator + (const double x,
00178     const df1_one_variable& y);
00179 
00180   df1_one_variable operator + (const df1_one_variable& x,
00181     const double y);
00182 
00183   df1_one_variable operator + (const df1_one_variable& x,
00184     const df1_one_variable& y);
00185   df1_one_variable operator - (double x,const df1_one_variable& y);
00186   df1_one_variable operator - (const df1_one_variable& x,double y);
00187 
00188   df1_one_variable operator - (const df1_one_variable& x,
00189     const df1_one_variable& y);
00190   df1_one_variable operator - (const df1_one_variable& x,
00191     const df1_one_variable& y);
00192   df1_one_variable operator / (const df1_one_variable& x,
00193     const df1_one_variable& y);
00194   df1_one_variable operator * (const df1_one_variable& x,
00195     const df1_one_variable& y);
00196 
00197 
00198   df1_one_variable operator - (const df1_one_variable& v);
00199   df1_one_matrix choleski_decomp(const df1_one_matrix& MM);
00200 
00201   df1_one_variable cumd_gamma(const df1_one_variable& x,
00202     const df1_one_variable& a);
00203 
00204 
00205   df1_one_variable gammln(const df1_one_variable& xx);
00206 #endif  // __DF11FUN__
00207