ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2f28.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 <df1b2fun.h>
12 
18 {
19  df1b2variable z;
20  double xu=*x.get_u();
21  double yu=*y.get_u();
22  double xpy3=::pow(xu,yu-3.0);
23  double xpy2=xu*xpy3;
24  double xpy1=xu*xpy2;
25  *z.get_u()=xu*xpy1;
26  double zu=*z.get_u();
27  double logx=log(xu);
28  double y1=yu-1.0;
29  double y2=yu-2.0;
30  double yy1=yu*y1;
31 
32  double dfx= yu*xpy1;
33  double dfy= zu*logx;
34  double dfxx=yy1*xpy2;
35  double dfxy=xpy1*(1.0+yu*logx);
36  double dfyy=dfy*logx;
37  double dfxxx=yy1*y2*xpy3;
38  double dfxxy=xpy2*(yy1*logx+2.0*yu-1.0);
39  double dfxyy=xpy1*logx*(yu*logx*logx+2.0);
40  double dfyyy=dfyy*logx;
41 
42  double * xd=x.get_u_dot();
43  double * yd=y.get_u_dot();
44  double * zd=z.get_u_dot();
45 
46  for (unsigned int i=0;i<df1b2variable::nvar;i++)
47  {
48  *zd++ = dfx * *xd++ + dfy * *yd++;
49  }
50 
51  f1b2gradlist->write_pass1(&x,&y,&z,
52  dfx,
53  dfy,
54  dfxx,dfxy,dfyy,
55  dfxxx,dfxxy,dfxyy,dfyyy);
56  return z;
57 }
58 
63 df1b2variable pow(double x,const df1b2variable& y)
64 {
65  df1b2variable z;
66  double yu=*y.get_u();
67  double zu=::pow(x,yu);
68  *z.get_u()=zu;
69  double logx=log(x);
70 
71  double dfy= zu*logx;
72  double dfyy=dfy*logx;
73  double dfyyy=dfyy*logx;
74 
75  double * yd=y.get_u_dot();
76  double * zd=z.get_u_dot();
77 
78  for (unsigned int i=0;i<df1b2variable::nvar;i++)
79  {
80  *zd++ = dfy * *yd++;
81  }
82 
84  dfy,
85  dfyy,
86  dfyyy);
87  return z;
88 }
89 
95 {
96  df1b2variable z;
97  double xu=*x.get_u();
98  double yu=*y.get_u();
99  double yinv=1.0/yu;
100  *z.get_u()=xu*yinv;
101  //double zu=*z.get_u();
102  double yinv2=yinv*yinv;
103  double yinv3=yinv2*yinv;
104 
105  double dfx= yinv;
106  double dfy= -xu*yinv2;
107  double dfxx= 0.0;
108  double dfxy=-yinv2;
109  double dfyy=2.0*xu*yinv3;
110  double dfxxx= 0.0;
111  double dfxxy= 0.0;
112  double dfxyy=2.0*yinv3;
113  double dfyyy=-6.0*xu*yinv3*yinv;
114 
115  double * xd=x.get_u_dot();
116  double * yd=y.get_u_dot();
117  double * zd=z.get_u_dot();
118 
119  for (unsigned int i=0;i<df1b2variable::nvar;i++)
120  {
121  *zd++ = dfx * *xd++ + dfy * *yd++;
122  }
123 
124  f1b2gradlist->write_pass1(&x,&y,&z,
125  dfx,
126  dfy,
127  dfxx,dfxy,dfyy,
128  dfxxx,dfxxy,dfxyy,dfyyy);
129  return z;
130 }
131 
137 {
138  df1b2variable z;
139  double yu=*y.get_u();
140  double yinv=1.0/yu;
141  *z.get_u()=x*yinv;
142  double zu=*z.get_u();
143 
144  /*
145  double dfy= -x*yinv*yinv;
146  double dfyy=2.0*x*yinv*yinv*yinv;
147  double dfyyy=-6.0*x*yinv*yinv*yinv*yinv;
148  */
149  double dfy=-zu*yinv;
150  double dfyy=-2.0*dfy*yinv;
151  double dfyyy=-3.0*dfyy*yinv;
152 
153  double * yd=y.get_u_dot();
154  double * zd=z.get_u_dot();
155 
156  for (unsigned int i=0;i<df1b2variable::nvar;i++)
157  {
158  *zd++ = dfy * *yd++;
159  }
160 
161  f1b2gradlist->write_pass1(&y,&z,
162  dfy,
163  dfyy,
164  dfyyy);
165  return z;
166 }
167 
173 {
174  df1b2variable z;
175  double xu=*x.get_u();
176  *z.get_u()=::pow(xu,y);
177  //double zu=*z.get_u();
178 
179  double dfx= y*::pow(xu,y-1.0);
180  double dfxx= y*(y-1.0)*::pow(xu,y-2.0);
181  double dfxxx= y*(y-1.0)*(y-2.0)*::pow(xu,y-3.0);
182  double * xd=x.get_u_dot();
183  double * zd=z.get_u_dot();
184 
185  for (unsigned int i=0;i<df1b2variable::nvar;i++)
186  {
187  *zd++ = dfx * *xd++ ;
188  }
189 
190  f1b2gradlist->write_pass1(&x,&z,
191  dfx,
192  dfxx,
193  dfxxx);
194  return z;
195 }
196 
197 /*
198 df1b2variable square(const df1b2variable& x)
199 {
200  df1b2variable z;
201  double xu=*x.get_u();
202  *z.get_u()=xu*xu
203  double zu=*z.get_u();
204 
205  double dfx=2.0*xu
206  double dfxx=2.0;
207  double dfxxx=0.0;
208  double * xd=x.get_u_dot();
209  double * zd=z.get_u_dot();
210 
211  for (unsigned int i=0;i<df1b2variable::nvar;i++)
212  {
213  *zd++ = dfx * *xd++ ;
214  }
215 
216  f1b2gradlist->write_pass1(&x,&z,
217  dfx,
218  dfxx,
219  dfxxx);
220  return z;
221 }
222 */
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
double * get_u() const
Definition: df1b2fun.h:228
#define x
Description not yet available.
Definition: df1b2fun.h:266
double * get_u_dot() const
Definition: df1b2fun.h:229
int write_pass1(const df1b2variable *px, const df1b2variable *py, df1b2variable *pz, df1b2function2 *pf)
Description not yet available.
Definition: df1b2f12.cpp:17
static unsigned int nvar
Definition: df1b2fun.h:290
Description not yet available.
d3_array operator/(const d3_array &m, const double d)
Author: David Fournier.
Definition: d3arr2b.cpp:14
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17