ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
dftweak.cpp
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  */
00011 #include <fvar.hpp>
00012 
00017 dfunction_tweaker::dfunction_tweaker(double _eps, double _mult):
00018   mult(_mult), eps(_eps), coffs(1, 3)
00019 {
00020   double e=eps;
00021   double e2=e*e;
00022   double e3=e*e2;
00023   double e4=e*e3;
00024   double e5=e*e4;
00025 
00026   dmatrix M(1,3,1,3);
00027   M(1,1)=e3;
00028   M(1,2)=e4;
00029   M(1,3)=e5;
00030 
00031   M(2,1)=3*e2;
00032   M(2,2)=4*e3;
00033   M(2,3)=5*e4;
00034 
00035   M(3,1)=6*e;
00036   M(3,2)=12*e2;
00037   M(3,3)=20*e3;
00038 
00039   dvector y(1,3);
00040   y(1)=mult*eps;
00041   y(2)=0.0;
00042   y(3)=0;
00043 
00044   coffs=solve(M,y);
00045 }
00046 
00051 dvariable dfunction_tweaker::operator () (const prevariable& x)
00052 {
00053   if (x>=eps &&x<=1-eps)
00054   {
00055     return x;
00056   }
00057   else if (x<eps)
00058   {
00059     dvariable x2=x*x;
00060     dvariable x3=x2*x;
00061     dvariable x4=x3*x;
00062     dvariable x5=x4*x;
00063     return mult*eps+x+coffs(3)*x5+coffs(2)*x4+coffs(1)*x3;
00064   }
00065   else
00066   {
00067     dvariable y=1-x;
00068     dvariable y2=y*y;
00069     dvariable y3=y2*y;
00070     dvariable y4=y3*y;
00071     dvariable y5=y4*y;
00072     return 1.0 -(mult*eps+y+coffs(3)*y5+coffs(2)*y4+coffs(1)*y3);
00073   }
00074 }