ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dftweak.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 #include <fvar.hpp>
12 
17 dfunction_tweaker::dfunction_tweaker(double _eps, double _mult):
18  mult(_mult), eps(_eps), coffs(1, 3)
19 {
20  double e=eps;
21  double e2=e*e;
22  double e3=e*e2;
23  double e4=e*e3;
24  double e5=e*e4;
25 
26  dmatrix M(1,3,1,3);
27  M(1,1)=e3;
28  M(1,2)=e4;
29  M(1,3)=e5;
30 
31  M(2,1)=3*e2;
32  M(2,2)=4*e3;
33  M(2,3)=5*e4;
34 
35  M(3,1)=6*e;
36  M(3,2)=12*e2;
37  M(3,3)=20*e3;
38 
39  dvector y(1,3);
40  y(1)=mult*eps;
41  y(2)=0.0;
42  y(3)=0;
43 
44  coffs=solve(M,y);
45 }
46 
52 {
53  if (x>=eps &&x<=1-eps)
54  {
55  return x;
56  }
57  else if (x<eps)
58  {
59  dvariable x2=x*x;
60  dvariable x3=x2*x;
61  dvariable x4=x3*x;
62  dvariable x5=x4*x;
63  return mult*eps+x+coffs(3)*x5+coffs(2)*x4+coffs(1)*x3;
64  }
65  else
66  {
67  dvariable y=1-x;
68  dvariable y2=y*y;
69  dvariable y3=y2*y;
70  dvariable y4=y3*y;
71  dvariable y5=y4*y;
72  return 1.0 -(mult*eps+y+coffs(3)*y5+coffs(2)*y4+coffs(1)*y3);
73  }
74 }
Base class for dvariable.
Definition: fvar.hpp:1315
#define x
Vector of double precision numbers.
Definition: dvector.h:50
dvector solve(const dmatrix &aa, const dvector &z)
Solve a linear system using LU decomposition.
Definition: dmat34.cpp:46
dvector coffs
Definition: fvar.hpp:5128
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
#define M
Definition: rngen.cpp:57
Description not yet available.
Definition: fvar.hpp:2819
dfunction_tweaker(double eps, double mult)
Description not yet available.
Definition: dftweak.cpp:17
dvector coffs
Definition: ftweak.cpp:14
double eps
Definition: ftweak.cpp:13
dvariable operator()(const prevariable &)
Description not yet available.
Definition: dftweak.cpp:51
double mult
Definition: ftweak.cpp:12
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518