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