ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
ftweak.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     double mult;
00013     double eps;
00014     dvector coffs;
00015 
00020 function_tweaker::function_tweaker(double _eps,double _mult):
00021   mult(_mult), eps(_eps), coffs(1,3)
00022 {
00023   double e=eps;
00024   double e2=e*e;
00025   double e3=e*e2;
00026   double e4=e*e3;
00027   double e5=e*e4;
00028 
00029   dmatrix M(1,3,1,3);
00030   M(1,1)=e3;
00031   M(1,2)=e4;
00032   M(1,3)=e5;
00033 
00034   M(2,1)=3*e2;
00035   M(2,2)=4*e3;
00036   M(2,3)=5*e4;
00037 
00038   M(3,1)=6*e;
00039   M(3,2)=12*e2;
00040   M(3,3)=20*e3;
00041 
00042   dvector y(1,3);
00043   y(1)=mult*e;
00044   y(2)=0.0;
00045   y(3)=0;
00046 
00047   coffs=solve(M,y);
00048 }
00049 
00054 double function_tweaker::operator () (double x)
00055 {
00056   if (x>=eps &&x<=1-eps)
00057   {
00058     return x;
00059   }
00060   else if (x<eps)
00061   {
00062     double x2=x*x;
00063     double x3=x2*x;
00064     double x4=x3*x;
00065     double x5=x4*x;
00066     return mult*eps+x+coffs(3)*x5+coffs(2)*x4+coffs(1)*x3;
00067   }
00068   else
00069   {
00070     double y=1-x;
00071     double y2=y*y;
00072     double y3=y2*y;
00073     double y4=y3*y;
00074     double y5=y4*y;
00075     return 1.0 -(mult*eps+y+coffs(3)*y5+coffs(2)*y4+coffs(1)*y3);
00076   }
00077 }