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