ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
posfunc.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  */
00007 
00013 #include <fvar.hpp>
00014 
00019 double dfposfun(const double &x, const double eps)
00020 {
00021   if (x>=eps)
00022   {
00023     return 1;
00024   }
00025   else
00026   {
00027     //double z=eps/(2-x/eps);
00028     double dfx=1.0/square(2-x/eps);
00029     //double z= 0.5*eps*(1.0+1.0/(3.0-2.0*x/eps));
00030     //double dfx=1.0/square(3.0-2.0*x/eps);
00031     return dfx;
00032   }
00033 }
00034 
00039 double dfposfun1(const double &x, const double eps)
00040 {
00041   if (x>=eps)
00042   {
00043     return 0;
00044   }
00045   else
00046   {
00047     double dfx=.02*(x-eps);
00048     return dfx;
00049   }
00050 }
00051 
00057 double posfun(const double &x, const double eps, const double& _pen)
00058 {
00059   double& pen=(double&)_pen;
00060   if (x>=eps)
00061   {
00062     return x;
00063   }
00064   else
00065   {
00066     pen+=.01*square(x-eps);
00067     //return 0.5*eps*(1.0+1.0/(3.0-2.0*x/eps));
00068     return eps/(2.0-x/eps);
00069   }
00070 }
00071 
00077 double posfun2(const double &x, const double eps, const double& _pen)
00078 {
00079   double& pen=(double&)_pen;
00080   if (x>=eps)
00081   {
00082     return x;
00083   }
00084   else
00085   {
00086     double y=eps-x;
00087     double tmp=y/eps;
00088     double tmp2=tmp*tmp;
00089     double tmp3=tmp2*tmp;
00090     pen+=.01*cube(tmp3);
00091     return eps/(1.0+tmp+tmp2+tmp3);
00092   }
00093 }