ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2tweak.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 <df1b2fun.h>
00012 
00017 df1b2function_tweaker::df1b2function_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 df1b2variable df1b2function_tweaker::operator () (const df1b2variable& x)
00052 {
00053   if (value(x)>=eps &&value(x)<=1-eps)
00054   {
00055     return x;
00056   }
00057   else if (value(x)<eps)
00058   {
00059     df1b2variable x2=x*x;
00060     df1b2variable x3=x2*x;
00061     df1b2variable x4=x3*x;
00062     df1b2variable x5=x4*x;
00063     return mult*eps+x+coffs(3)*x5+coffs(2)*x4+coffs(1)*x3;
00064   }
00065   else
00066   {
00067     df1b2variable y=1-x;
00068     df1b2variable y2=y*y;
00069     df1b2variable y3=y2*y;
00070     df1b2variable y4=y3*y;
00071     df1b2variable y5=y4*y;
00072     double tmp=value(mult*eps+y+coffs(3)*y5+coffs(2)*y4+coffs(1)*y3);
00073     if (tmp>1.0)
00074       cout << "H" << endl;
00075     return 1.0 -(mult*eps+y+coffs(3)*y5+coffs(2)*y4+coffs(1)*y3);
00076   }
00077 }