ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
posfunv.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 
00012 #include <fvar.hpp>
00013 
00032 dvariable posfun(const dvariable &x, const double eps, const prevariable& _pen)
00033 {
00034   dvariable& pen= (dvariable&) _pen;
00035   if (x>=eps)
00036   {
00037     return x;
00038   }
00039   else
00040   {
00041     //dvariable y=1.0-x/eps;
00042     pen+=.01*square(x-eps);
00043     return eps/(2-x/eps);
00044   }
00045 }
00046 
00052 dvariable posfun(const dvariable &x, const double eps, const dvariable& _pen)
00053 {
00054   dvariable& pen= (dvariable&) _pen;
00055   if (x>=eps)
00056   {
00057     return x;
00058   }
00059   else
00060   {
00061     //dvariable y=1.0-x/eps;
00062     pen+=.01*square(x-eps);
00063     return eps/(2-x/eps);
00064   }
00065 }
00066 
00088 dvariable posfun2(const dvariable &x, const double eps, const prevariable& _pen)
00089 {
00090   dvariable& pen= (dvariable&) _pen;
00091   if (x>=eps)
00092   {
00093     return x;
00094   }
00095   else
00096   {
00097     dvariable y=eps-x;
00098     dvariable tmp=y/eps;
00099     dvariable tmp2=tmp*tmp;
00100     dvariable tmp3=tmp2*tmp;
00101     pen+=.01*cube(tmp3);
00102     return eps/(1.0+tmp+tmp2+tmp3);
00103   }
00104 }
00105 
00110 dvariable dfposfun(const prevariable&x,const double eps)
00111 {
00112   if (x>=eps)
00113   {
00114     return 1;
00115   }
00116   else
00117   {
00118     //double z=eps/(2-x/eps);
00119     dvariable dfx=1.0/square(2-x/eps);
00120     return dfx;
00121   }
00122 }