ADMB Documentation  11.1.2493
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_fn2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_fn2.cpp 2304 2014-09-05 23:25:48Z 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 
00029 /*
00030   prevariable& daves_kludge1(const prevariable& v1)
00031   {
00032     if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN)
00033       gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
00034 
00035     double cx=value(v1);
00036     double fval;
00037     double tmp;
00038     double dftmp;
00039     double tmp2;
00040     double tmp3;
00041     int i=cx;
00042     if (cx-i <= 0.5)
00043     {
00044       tmp=cx-i;
00045       tmp2=tmp*tmp;
00046       tmp3=tmp*tmp*tmp;
00047       fval= 24*tmp3-64*tmp3*tmp+48*tmp3*tmp2;
00048     }
00049     else
00050     {
00051       tmp=1-(cx-i);
00052       tmp2=tmp*tmp;
00053       tmp3=tmp*tmp*tmp;
00054       fval=1.-24*tmp3+64*tmp3*tmp-48*tmp3*tmp2;
00055     }
00056 
00057     if (cx-i <= 0.5)
00058     {
00059       //fval= 24*tmp3-64*tmp3*tmp+48*tmp3*tmp2;
00060       double dftmp3=24-64*tmp+48*tmp2;
00061       dftmp=-64*tmp3;
00062       double dftmp2=48*tmp3;
00063       //double tmp3=tmp*tmp*tmp;
00064       dftmp+=3.*tmp2*dftmp3;
00065       //double tmp2=tmp*tmp;
00066       dftmp+=2.*tmp*dftmp2;
00067     }
00068     else
00069     {
00070       //fval=1.-24*tmp3+64*tmp3*tmp-48*tmp3*tmp2;
00071       double dftmp3=-24+64*tmp-48*tmp2;
00072       dftmp=+64*tmp3;
00073       double dftmp2=-48*tmp3;
00074       //double tmp3=tmp*tmp*tmp;
00075       dftmp+=3.*tmp2*dftmp3;
00076       //double tmp2=tmp*tmp;
00077       dftmp+=2.*tmp*dftmp2;
00078       //double tmp=1-(cx-i);
00079       dftmp=-dftmp;
00080     }
00081 
00082     gradient_structure::RETURN_PTR->v->x=fval;
00083     gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation,
00084       &(gradient_structure::RETURN_PTR->v->x), &(v1.v->x),dftmp);
00085    return(*gradient_structure::RETURN_PTR);
00086  }
00087 */