ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_fn2.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 // file fvar_fn.cpp
12 // math.h functions involving prevariables
13 #include "fvar.hpp"
14 
15 #include <stdio.h>
16 #include <math.h>
17 
23 {
24  return 0.5*(x+y);
25 }
26 
27 /*
28  prevariable& daves_kludge1(const prevariable& v1)
29  {
30  if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN)
31  gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
32 
33  double cx=value(v1);
34  double fval;
35  double tmp;
36  double dftmp;
37  double tmp2;
38  double tmp3;
39  int i=cx;
40  if (cx-i <= 0.5)
41  {
42  tmp=cx-i;
43  tmp2=tmp*tmp;
44  tmp3=tmp*tmp*tmp;
45  fval= 24*tmp3-64*tmp3*tmp+48*tmp3*tmp2;
46  }
47  else
48  {
49  tmp=1-(cx-i);
50  tmp2=tmp*tmp;
51  tmp3=tmp*tmp*tmp;
52  fval=1.-24*tmp3+64*tmp3*tmp-48*tmp3*tmp2;
53  }
54 
55  if (cx-i <= 0.5)
56  {
57  //fval= 24*tmp3-64*tmp3*tmp+48*tmp3*tmp2;
58  double dftmp3=24-64*tmp+48*tmp2;
59  dftmp=-64*tmp3;
60  double dftmp2=48*tmp3;
61  //double tmp3=tmp*tmp*tmp;
62  dftmp+=3.*tmp2*dftmp3;
63  //double tmp2=tmp*tmp;
64  dftmp+=2.*tmp*dftmp2;
65  }
66  else
67  {
68  //fval=1.-24*tmp3+64*tmp3*tmp-48*tmp3*tmp2;
69  double dftmp3=-24+64*tmp-48*tmp2;
70  dftmp=+64*tmp3;
71  double dftmp2=-48*tmp3;
72  //double tmp3=tmp*tmp*tmp;
73  dftmp+=3.*tmp2*dftmp3;
74  //double tmp2=tmp*tmp;
75  dftmp+=2.*tmp*dftmp2;
76  //double tmp=1-(cx-i);
77  dftmp=-dftmp;
78  }
79 
80  gradient_structure::RETURN_PTR->v->x=fval;
81  gradient_structure::get()->GRAD_STACK1->set_gradient_stack(default_evaluation,
82  &(gradient_structure::RETURN_PTR->v->x), &(v1.v->x),dftmp);
83  return(*gradient_structure::RETURN_PTR);
84  }
85 */
Base class for dvariable.
Definition: fvar.hpp:1315
#define x
double avg(double x, double y)
Average of two numbers; constant objects.
Definition: dvector.cpp:42
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518