ADMB Documentation  11.1.2274
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_fn2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_fn2.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file fvar_fn.cpp
00012 // math.h functions involving prevariables
00013 #include "fvar.hpp"
00014 
00015 #include <stdio.h>
00016 #include <math.h>
00017 
00018 void gradfree(dlink *);
00019 
00024 dvariable avg( const prevariable& x,const prevariable& y)
00025 {
00026   return 0.5*(x+y);
00027 }
00028 
00033   prevariable& daves_kludge1(const prevariable& v1)
00034   {
00035     if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN)
00036       gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
00037 
00038     double cx=value(v1);
00039     double fval;
00040     double tmp;
00041     double dftmp;
00042     double tmp2;
00043     double tmp3;
00044     int i=cx;
00045     if (cx-i <= 0.5)
00046     {
00047       tmp=cx-i;
00048       tmp2=tmp*tmp;
00049       tmp3=tmp*tmp*tmp;
00050       fval= 24*tmp3-64*tmp3*tmp+48*tmp3*tmp2;
00051     }
00052     else
00053     {
00054       tmp=1-(cx-i);
00055       tmp2=tmp*tmp;
00056       tmp3=tmp*tmp*tmp;
00057       fval=1.-24*tmp3+64*tmp3*tmp-48*tmp3*tmp2;
00058     }
00059 
00060     if (cx-i <= 0.5)
00061     {
00062       //fval= 24*tmp3-64*tmp3*tmp+48*tmp3*tmp2;
00063       double dftmp3=24-64*tmp+48*tmp2;
00064       dftmp=-64*tmp3;
00065       double dftmp2=48*tmp3;
00066       //double tmp3=tmp*tmp*tmp;
00067       dftmp+=3.*tmp2*dftmp3;
00068       //double tmp2=tmp*tmp;
00069       dftmp+=2.*tmp*dftmp2;
00070     }
00071     else
00072     {
00073       //fval=1.-24*tmp3+64*tmp3*tmp-48*tmp3*tmp2;
00074       double dftmp3=-24+64*tmp-48*tmp2;
00075       dftmp=+64*tmp3;
00076       double dftmp2=-48*tmp3;
00077       //double tmp3=tmp*tmp*tmp;
00078       dftmp+=3.*tmp2*dftmp3;
00079       //double tmp2=tmp*tmp;
00080       dftmp+=2.*tmp*dftmp2;
00081       //double tmp=1-(cx-i);
00082       dftmp=-dftmp;
00083     }
00084 
00085     gradient_structure::RETURN_PTR->v->x=fval;
00086     gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation,
00087       &(gradient_structure::RETURN_PTR->v->x), &(v1.v->x),dftmp);
00088    return(*gradient_structure::RETURN_PTR);
00089  }