ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df32fun.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>
14 
19 {
20  v[0] = x.v[0];
21  v[1] = x.v[1];
22  v[2] = x.v[2];
23  v[3] = x.v[3];
24  v[4] = x.v[4];
25  v[5] = x.v[5];
26  v[6] = x.v[6];
27  v[7] = x.v[7];
28  v[8] = x.v[8];
29  v[9] = x.v[9];
30 }
31 
37  {
40  shape=m2.shape;
41  if (shape)
42  {
43  (shape->ncopies)++;
44  }
45  v = m2.v;
46  }
47 
50 {
51  deallocate();
52 }
55 {
56  if(shape)
57  {
58  if (shape->ncopies)
59  {
60  (shape->ncopies)--;
61  }
62  else
63  {
65  delete [] v;
66  delete shape;
67  allocate();
68  }
69  }
70 }
71 
77  {
78  int mmin=v.indexmin();
79  int mmax=v.indexmax();
80  dvector cv(mmin,mmax);
81  for (int i=mmin;i<=mmax;i++)
82  {
83  cv(i)=value(v(i));
84  }
85  return cv;
86  }
87 
92 {
93  int mmin = indexmin();
94  int mmax = indexmax();
95  for (int i = mmin; i <= mmax; ++i)
96  {
97  (*this)(i) = 0.0;
98  }
99 }
104 {
105  allocate();
106 }
107 
113  {
114  allocate(min,max);
115  }
116 
125 {
126  index_min = min;
127  index_max = max;
128  v = new df3_two_variable[
129  static_cast<unsigned int>(max < min ? 0 : max - min + 1)];
130  if (v == 0)
131  {
132  cerr << "error allocating memory in df3_two_vector\n";
133  ad_exit(1);
134  }
135  if ((shape = new vector_shapex(min, max, v)) == NULL)
136  {
137  cerr << "Error trying to allocate memory for df3_two_vector\n";
138  ad_exit(1);
139  }
140  v -= min;
141 }
146 {
147  index_min = 0;
148  index_max = -1;
149  v = 0;
150  shape = 0;
151 }
152 
158  {
159  int rmin=v.indexmin();
160  int rmax=v.indexmax();
161  dmatrix cm(rmin,rmax);
162  for (int i=rmin;i<=rmax;i++)
163  {
164  int cmin=v(i).indexmin();
165  int cmax=v(i).indexmax();
166  cm(i).allocate(cmin,cmax);
167  for (int j=cmin;j<=cmax;j++)
168  {
169  cm(i,j)=value(v(i,j));
170  }
171  }
172  return cm;
173  }
174 
180  {
181  index_min=m2.index_min;
182  index_max=m2.index_max;
183  shape=m2.shape;
184  if (shape)
185  {
186  (shape->ncopies)++;
187  }
188  v = m2.v;
189  }
192 {
193  deallocate();
194 }
197 {
198  if (shape)
199  {
200  if (shape->ncopies)
201  {
202  (shape->ncopies)--;
203  }
204  else
205  {
206  v = (df3_two_vector*) (shape->get_pointer());
207  delete [] v;
208  v = nullptr;
209  delete shape;
210  shape = nullptr;
211  index_min = 0;
212  index_max = -1;
213  }
214  }
215 }
216 
222  {
223  int mmin=indexmin();
224  int mmax=indexmax();
225  for (int i=mmin;i<=mmax;i++)
226  {
227  (*this)(i).initialize();
228  }
229  }
230 
240 df3_two_matrix::df3_two_matrix(int rmin,int rmax,int cmin,int cmax)
241 {
242  index_min = rmin;
243  index_max = rmax;
244  v = new df3_two_vector[
245  static_cast<unsigned int>(rmax < rmin ? 0 : rmax - rmin + 1)];
246  if (v == 0)
247  {
248  cerr << "error allocating memory in df3_two_matrix" << endl;
249  ad_exit(1);
250  }
251  if ((shape = new mat_shapex(v)) == NULL)
252  {
253  cerr << "Error trying to allocate memory for df3_two_vector\n";
254  ad_exit(1);
255  }
256  v-=rmin;
257  for (int i = rmin; i <= rmax; ++i)
258  {
259  v[i].allocate(cmin, cmax);
260  }
261 }
266 {
267  *get_u() -= *_v.get_u();
268  *get_u_x() -= *_v.get_u_x();
269  *get_u_y() -= *_v.get_u_y();
270  *get_u_xx() -= *_v.get_u_xx();
271  *get_u_xy() -= *_v.get_u_xy();
272  *get_u_yy() -= *_v.get_u_yy();
273  *get_u_xxx() -= *_v.get_u_xxx();
274  *get_u_xxy() -= *_v.get_u_xxy();
275  *get_u_xyy() -= *_v.get_u_xyy();
276  *get_u_yyy() -= *_v.get_u_yyy();
277  return *this;
278 }
279 
285 {
287 
288  *z.get_u() = - *v.get_u();
289 
290  *z.get_u_x() = -(*v.get_u_x());
291  *z.get_u_y() = -(*v.get_u_y());
292  *z.get_u_xx() = -(*v.get_u_xx());
293  *z.get_u_xy() = -(*v.get_u_xy());
294  *z.get_u_yy() = -(*v.get_u_yy());
295  *z.get_u_xxx() = -(*v.get_u_xxx());
296  *z.get_u_xxy() = -(*v.get_u_xxy());
297  *z.get_u_xyy() = -(*v.get_u_xyy());
298  *z.get_u_yyy() = -(*v.get_u_yyy());
299 
300  return z;
301 }
306 {
307  *get_u() += *_v.get_u();
308  *get_u_x() += *_v.get_u_x();
309  *get_u_y() += *_v.get_u_y();
310  *get_u_xx() += *_v.get_u_xx();
311  *get_u_xy() += *_v.get_u_xy();
312  *get_u_yy() += *_v.get_u_yy();
313  *get_u_xxx() += *_v.get_u_xxx();
314  *get_u_xxy() += *_v.get_u_xxy();
315  *get_u_xyy() += *_v.get_u_xyy();
316  *get_u_yyy() += *_v.get_u_yyy();
317 
318  return *this;
319 }
324 {
325  *get_u() += _v;
326 
327  return *this;
328 }
333 {
334  *get_u() -= _v;
335  return *this;
336 }
341 {
342  df3_two_variable x = *this * _v;
343  *this = x;
344  return *this;
345 }
350 {
351  *get_u() *= _v;
352  *get_u_x() *= _v;
353  *get_u_y() *= _v;
354  *get_u_xx() *= _v;
355  *get_u_xy() *= _v;
356  *get_u_yy() *= _v;
357  *get_u_xxx() *= _v;
358  *get_u_xxy() *= _v;
359  *get_u_xyy() *= _v;
360  *get_u_yyy() *= _v;
361 
362  return *this;
363 }
364 
370  {
371  df3_two_variable x=*this / y;
372  *this=x;
373  return *this;
374  }
375 
380 int operator <(const df3_two_variable & x, double n)
381 {
382  return value(x) < n;
383 }
384 
389 int operator >(const df3_two_variable & x, double n)
390 {
391  return value(x) > n;
392 }
393 
398 int operator >=(const df3_two_variable & x, double n)
399 {
400  return value(x) >= n;
401 }
402 
408 {
409  return value(x) == value(n);
410 }
411 
416 int operator ==(const df3_two_variable & x, double n)
417 {
418  return value(x) == n;
419 }
420 
425 int operator ==(double x, const df3_two_variable & n)
426 {
427  return x == value(n);
428 }
429 
435 {
436  return value(x) < value(n);
437 }
438 
444 {
445  return value(x) > value(n);
446 }
447 
453  double zp,double zp2,double zp3)
454 {
455  //*z.get_u() = u;
456 
457  *z.get_u_x() = zp* *x.get_u_x();
458 
459  *z.get_u_y() = zp* *x.get_u_y();
460 
461  *z.get_u_xx() = zp2 * square(*x.get_u_x())
462  + zp * *x.get_u_xx();
463 
464  *z.get_u_xy() = zp2 * *x.get_u_x() * *x.get_u_y()
465  + zp * *x.get_u_xy();
466 
467  *z.get_u_yy() = zp2 * square(*x.get_u_y())
468  + zp * *x.get_u_yy();
469 
470  *z.get_u_xxx() = zp3 * cube(*x.get_u_x())
471  + 3.0 * zp2 * *x.get_u_x() * *x.get_u_xx()
472  + zp * *x.get_u_xxx();
473 
474  *z.get_u_xxy() = zp3 * square(*x.get_u_x())* *x.get_u_y()
475  + 2.0* zp2 * *x.get_u_x() * *x.get_u_xy()
476  + zp2 * *x.get_u_y() * *x.get_u_xx()
477  + zp * *x.get_u_xxy();
478 
479  *z.get_u_xyy() = zp3 * square(*x.get_u_y())* *x.get_u_x()
480  + 2.0* zp2 * *x.get_u_y() * *x.get_u_xy()
481  + zp2 * *x.get_u_x() * *x.get_u_yy()
482  + zp * *x.get_u_xyy();
483 
484 
485  *z.get_u_yyy() = zp3 * cube(*x.get_u_y())
486  + 3.0 * zp2 * *x.get_u_y() * *x.get_u_yy()
487  + zp * *x.get_u_yyy();
488 }
489 
495  const df3_two_variable& y, double u,
496  double f_u,double f_v,double f_uu,double f_uv,double f_vv,double f_uuu,
497  double f_uuv,double f_uvv,double f_vvv)
498 {
499  *z.get_u() = u;
500 
501  *z.get_u_x() = f_u* *x.get_u_x()
502  + f_v* *y.get_u_x();
503 
504  *z.get_u_y() = f_u* *x.get_u_y()
505  + f_v* *y.get_u_y();
506 
507  *z.get_u_xx() = f_uu * square(*x.get_u_x())
508  + f_u * *x.get_u_xx()
509  + f_vv * square(*y.get_u_x())
510  + f_v * *y.get_u_xx()
511  + 2.0 * f_uv * *x.get_u_x() * *y.get_u_x();
512 
513  *z.get_u_xy() = f_uu * *x.get_u_x() * *x.get_u_y()
514  + f_u * *x.get_u_xy()
515  + f_vv * *y.get_u_x() * *y.get_u_y()
516  + f_v * *y.get_u_xy()
517  + f_uv * (*x.get_u_x() * *y.get_u_y()
518  + *x.get_u_y() * *y.get_u_x());
519 
520  *z.get_u_yy() = f_uu * square(*x.get_u_y())
521  + f_u * *x.get_u_yy()
522  + f_vv * square(*y.get_u_y())
523  + f_v * *y.get_u_yy()
524  + 2.0 * f_uv * *x.get_u_y() * *y.get_u_y();
525 
526 
527  *z.get_u_xxx() = f_uuu * cube(*x.get_u_x())
528  + 3.0 * f_uu * *x.get_u_x() * *x.get_u_xx()
529  + f_u * *x.get_u_xxx()
530  + f_vvv * cube(*y.get_u_x())
531  + 3.0 * f_vv * *y.get_u_x() * *y.get_u_xx()
532  + f_v * *y.get_u_xxx()
533  + 3.0 * f_uuv * square(*x.get_u_x()) * *y.get_u_x()
534  + 3.0 * f_uvv * *x.get_u_x()* square(*y.get_u_x())
535  + 3.0* f_uv * *x.get_u_xx() * *y.get_u_x()
536  + 3.0* f_uv * *x.get_u_x() * *y.get_u_xx();
537 
538  *z.get_u_xxy() = f_uuu * square(*x.get_u_x())* *x.get_u_y()
539  + 2.0 * f_uu * *x.get_u_x() * *x.get_u_xy()
540  + f_uu * *x.get_u_y() * *x.get_u_xx()
541  + f_u * *x.get_u_xxy()
542  + f_vvv * square(*y.get_u_x())* *y.get_u_y()
543  + 2.0 * f_vv * *y.get_u_x() * *y.get_u_xy()
544  + f_vv * *y.get_u_xx() * *y.get_u_y()
545  + f_v * *y.get_u_xxy()
546  + f_uuv * square(*x.get_u_x()) * *y.get_u_y()
547  + 2.0* f_uuv * *x.get_u_x() * *x.get_u_y() * *y.get_u_x()
548  + f_uvv * *x.get_u_y()* square(*y.get_u_x())
549  + 2.0 * f_uvv * *x.get_u_x()* *y.get_u_x() * *y.get_u_y()
550  + f_uv * *x.get_u_xx() * *y.get_u_y()
551  + f_uv * *x.get_u_y() * *y.get_u_xx()
552  + 2.0* f_uv * *x.get_u_xy() * *y.get_u_x()
553  + 2.0* f_uv * *x.get_u_x() * *y.get_u_xy();
554 
555  *z.get_u_xyy() = f_uuu * square(*x.get_u_y())* *x.get_u_x()
556  + 2.0 * f_uu * *x.get_u_y() * *x.get_u_xy()
557  + f_uu * *x.get_u_x() * *x.get_u_yy()
558  + f_u * *x.get_u_xyy()
559  + f_vvv * square(*y.get_u_y())* *y.get_u_x()
560  + 2.0 * f_vv * *y.get_u_y() * *y.get_u_xy()
561  + f_vv * *y.get_u_yy() * *y.get_u_x()
562  + f_v * *y.get_u_xyy()
563  + f_uuv * square(*x.get_u_y()) * *y.get_u_x()
564  + 2.0* f_uuv * *x.get_u_y() * *x.get_u_x() * *y.get_u_y()
565  + f_uvv * *x.get_u_x()* square(*y.get_u_y())
566  + 2.0 * f_uvv * *x.get_u_y()* *y.get_u_y() * *y.get_u_x()
567  + f_uv * *x.get_u_yy() * *y.get_u_x()
568  + f_uv * *x.get_u_x() * *y.get_u_yy()
569  + 2.0* f_uv * *x.get_u_xy() * *y.get_u_y()
570  + 2.0* f_uv * *x.get_u_y() * *y.get_u_xy();
571 
572 
573  *z.get_u_yyy() = f_uuu * cube(*x.get_u_y())
574  + 3.0 * f_uu * *x.get_u_y() * *x.get_u_yy()
575  + f_u * *x.get_u_yyy()
576  + f_vvv * cube(*y.get_u_y())
577  + 3.0 * f_vv * *y.get_u_y() * *y.get_u_yy()
578  + f_v * *y.get_u_yyy()
579  + 3.0 * f_uuv * square(*x.get_u_y()) * *y.get_u_y()
580  + 3.0 * f_uvv * *x.get_u_y()* square(*y.get_u_y())
581  + 3.0 * f_uv * *x.get_u_yy() * *y.get_u_y()
582  + 3.0 * f_uv * *x.get_u_y() * *y.get_u_yy();
583 }
584 
590  {
592  double u=::sqrt(*x.get_u());
593  *z.get_u()=u;
594  double xinv=1.0/(*x.get_u());
595  double zp=0.5/u;
596  double zp2=-0.5*zp*xinv;
597  double zp3=-1.5*zp2*xinv;
598 
599 
600  set_derivatives(z,x,u,zp,zp2,zp3);
601 
602  return z;
603  }
604 
610  {
612  double cx=value(x);
613  double d=1.0/(1+square(cx));
614  double d2=square(d);
615  double u=::atan(cx);
616  *z.get_u()=u;
617  double zp=d;
618  double zp2=-2.0*cx*d2;
619  double zp3=-2.0*d2+8*cx*cx*d*d2;
620 
621  set_derivatives(z,x,u,zp,zp2,zp3);
622  return z;
623  }
624 
630  {
632  double u=value(x);
633  *z.get_u()=u*u;
634  double zp=2.0*u;
635  double zp2=2.0;
636  double zp3=0.0;
637 
638  set_derivatives(z,x,u,zp,zp2,zp3);
639  return z;
640  }
641 
647  {
649  double u=::tan(*x.get_u());
650  *z.get_u()=u;
651  double v=1.0/::cos(*x.get_u());
652  double w=::sin(*x.get_u());
653  double v2=v*v;
654  double zp=v2;
655  double zp2=2.0*w*v2*v;
656  double zp3=(4.0*w*w+2.0)*v2*v2;
657 
658  set_derivatives(z,x,u,zp,zp2,zp3);
659  return z;
660  }
661 
667  {
669  double u=::sin(*x.get_u());
670  *z.get_u()=u;
671  double zp=::cos(*x.get_u());
672  double zp2=-u;
673  double zp3=-zp;
674 
675  set_derivatives(z,x,u,zp,zp2,zp3);
676  return z;
677  }
678 
684  {
686  if (value(v)>=0)
687  {
688  *z.get_u() = *v.get_u();
689  *z.get_u_x() = *v.get_u_x();
690  *z.get_u_y() = *v.get_u_y();
691  *z.get_u_xx() = *v.get_u_xx();
692  *z.get_u_xy() = *v.get_u_xy();
693  *z.get_u_yy() = *v.get_u_yy();
694  *z.get_u_xxx() = *v.get_u_xxx();
695  *z.get_u_xxy() = *v.get_u_xxy();
696  *z.get_u_xyy() = *v.get_u_xyy();
697  *z.get_u_yyy() = *v.get_u_yyy();
698  }
699  else
700  {
701  *z.get_u() = -*v.get_u();
702  *z.get_u_x() = -*v.get_u_x();
703  *z.get_u_y() = -*v.get_u_y();
704  *z.get_u_xx() = -*v.get_u_xx();
705  *z.get_u_xy() = -*v.get_u_xy();
706  *z.get_u_yy() = -*v.get_u_yy();
707  *z.get_u_xxx() = -*v.get_u_xxx();
708  *z.get_u_xxy() = -*v.get_u_xxy();
709  *z.get_u_xyy() = -*v.get_u_xyy();
710  *z.get_u_yyy() = -*v.get_u_yyy();
711  }
712 
713  return z;
714  }
715 
721  {
723  double u=::log(*x.get_u());
724  *z.get_u()=u;
725  double zp=1/(*x.get_u());
726  double zp2=-zp*zp;
727  double zp3=-2.0*zp*zp2;
728 
729  set_derivatives(z,x,u,zp,zp2,zp3);
730  return z;
731  }
732 
738  {
740  double u=::exp(*x.get_u());
741  *z.get_u()=u;
742  double zp=u;
743  double zp2=u;
744  double zp3=u;
745 
746  set_derivatives(z,x,u,zp,zp2,zp3);
747  return z;
748  }
749 
755  const df3_two_variable& y)
756  {
758  z=exp(y*log(x));
759  return z;
760  }
761 
767  {
769  double xinv=1.0/(*x.get_u());
770  *z.get_u()=xinv;
771  double zp=-xinv*xinv;
772  double zp2=-2.0*zp*xinv;
773  double zp3=-3.0*zp2*xinv;
774 
775  set_derivatives(z,x,xinv,zp,zp2,zp3);
776 
777  return z;
778  }
779 
785  {
786  *get_u() = *x.get_u();
787  *get_u_x() = *x.get_u_x();
788  *get_u_y() = *x.get_u_y();
789  *get_u_xx() = *x.get_u_xx();
790  *get_u_xy() = *x.get_u_xy();
791  *get_u_yy() = *x.get_u_yy();
792  *get_u_xxx() = *x.get_u_xxx();
793  *get_u_xxy() = *x.get_u_xxy();
794  *get_u_xyy() = *x.get_u_xyy();
795  *get_u_yyy() = *x.get_u_yyy();
796  return *this;
797  }
798 
804  {
805  *get_u() = x;
806  *get_u_x() =0.0;
807  *get_u_y() =0.0;
808  *get_u_xx() =0.0;
809  *get_u_xy() =0.0;
810  *get_u_yy() =0.0;
811  *get_u_xxx() =0.0;
812  *get_u_xxy() =0.0;
813  *get_u_xyy() =0.0;
814  *get_u_yyy() =0.0;
815  return *this;
816  }
817 
823  const df3_two_variable& y)
824  {
826  double u= *x.get_u() * *y.get_u();
827  *z.get_u() = u;
828  double f_u=*y.get_u();
829  double f_v=*x.get_u();
830  double f_uu=0.0;
831  double f_uv=1.0;
832  double f_vv=0.0;
833  double f_uuu=0.0;
834  double f_uuv=0.0;
835  double f_uvv=0.0;
836  double f_vvv=0.0;
837  set_derivatives(z,x,y,u,
838  f_u, f_v,
839  f_uu, f_uv, f_vv,
840  f_uuu, f_uuv, f_uvv, f_vvv);
841  return z;
842  }
843 
849  const df3_two_variable& y)
850  {
852  *z.get_u() = x * *y.get_u();
853  *z.get_u_x() = x * *y.get_u_x();
854  *z.get_u_y() = x * *y.get_u_y();
855  *z.get_u_xx() = x * *y.get_u_xx();
856  *z.get_u_xy() = x * *y.get_u_xy();
857  *z.get_u_yy() = x * *y.get_u_yy();
858  *z.get_u_xxx() = x * *y.get_u_xxx();
859  *z.get_u_xxy() = x * *y.get_u_xxy();
860  *z.get_u_xyy() = x * *y.get_u_xyy();
861  *z.get_u_yyy() = x * *y.get_u_yyy();
862 
863  return z;
864  }
865 
871  double x)
872  {
874  *z.get_u() = x * *y.get_u();
875  *z.get_u_x() = x * *y.get_u_x();
876  *z.get_u_y() = x * *y.get_u_y();
877  *z.get_u_xx() = x * *y.get_u_xx();
878  *z.get_u_xy() = x * *y.get_u_xy();
879  *z.get_u_yy() = x * *y.get_u_yy();
880  *z.get_u_xxx() = x * *y.get_u_xxx();
881  *z.get_u_xxy() = x * *y.get_u_xxy();
882  *z.get_u_xyy() = x * *y.get_u_xyy();
883  *z.get_u_yyy() = x * *y.get_u_yyy();
884 
885  return z;
886  }
887 
893  double y)
894  {
895  double u=1/y;
896  return x*u;
897  }
898 
904  const df3_two_variable& y)
905  {
906  df3_two_variable u=inv(y);
907  return x*u;
908  }
909 
915  const df3_two_variable& y)
916  {
917  df3_two_variable u=inv(y);
918  return x*u;
919  }
920 
926  {
928  *z.get_u() = x + *y.get_u();
929  *z.get_u_x() = *y.get_u_x();
930  *z.get_u_y() = *y.get_u_y();
931  *z.get_u_xx() = *y.get_u_xx();
932  *z.get_u_xy() = *y.get_u_xy();
933  *z.get_u_yy() = *y.get_u_yy();
934  *z.get_u_xxx() = *y.get_u_xxx();
935  *z.get_u_xxy() = *y.get_u_xxy();
936  *z.get_u_xyy() = *y.get_u_xyy();
937  *z.get_u_yyy() = *y.get_u_yyy();
938  return z;
939  }
940 
946  {
948  *z.get_u() = *x.get_u() + y;
949  *z.get_u_x() = *x.get_u_x();
950  *z.get_u_y() = *x.get_u_y();
951  *z.get_u_xx() = *x.get_u_xx();
952  *z.get_u_xy() = *x.get_u_xy();
953  *z.get_u_yy() = *x.get_u_yy();
954  *z.get_u_xxx() = *x.get_u_xxx();
955  *z.get_u_xxy() = *x.get_u_xxy();
956  *z.get_u_xyy() = *x.get_u_xyy();
957  *z.get_u_yyy() = *x.get_u_yyy();
958  return z;
959  }
960 
966  const df3_two_variable& y)
967  {
969  *z.get_u() = *x.get_u() + *y.get_u();
970  *z.get_u_x() = *x.get_u_x() + *y.get_u_x();
971  *z.get_u_y() = *x.get_u_y()+*y.get_u_y();
972  *z.get_u_xx() = *x.get_u_xx()+ *y.get_u_xx();
973  *z.get_u_xy() = *x.get_u_xy()+ *y.get_u_xy();
974  *z.get_u_yy() = *x.get_u_yy()+ *y.get_u_yy();
975  *z.get_u_xxx() = *x.get_u_xxx()+ *y.get_u_xxx();
976  *z.get_u_xxy() = *x.get_u_xxy()+ *y.get_u_xxy();
977  *z.get_u_xyy() = *x.get_u_xyy()+ *y.get_u_xyy();
978  *z.get_u_yyy() = *x.get_u_yyy()+ *y.get_u_yyy();
979  return z;
980  }
981 
987  const df3_two_variable& y)
988  {
990  *z.get_u() = *x.get_u() - *y.get_u();
991  *z.get_u_x() = *x.get_u_x() - *y.get_u_x();
992  *z.get_u_y() = *x.get_u_y() - *y.get_u_y();
993  *z.get_u_xx() = *x.get_u_xx() - *y.get_u_xx();
994  *z.get_u_xy() = *x.get_u_xy() - *y.get_u_xy();
995  *z.get_u_yy() = *x.get_u_yy() - *y.get_u_yy();
996  *z.get_u_xxx() = *x.get_u_xxx() - *y.get_u_xxx();
997  *z.get_u_xxy() = *x.get_u_xxy() - *y.get_u_xxy();
998  *z.get_u_xyy() = *x.get_u_xyy() - *y.get_u_xyy();
999  *z.get_u_yyy() = *x.get_u_yyy() - *y.get_u_yyy();
1000  return z;
1001  }
1002 
1008  const df3_two_variable& y)
1009  {
1010  df3_two_variable z;
1011  *z.get_u() = x - *y.get_u();
1012  *z.get_u_x() = - *y.get_u_x();
1013  *z.get_u_y() = - *y.get_u_y();
1014  *z.get_u_xx() = - *y.get_u_xx();
1015  *z.get_u_xy() = - *y.get_u_xy();
1016  *z.get_u_yy() = - *y.get_u_yy();
1017  *z.get_u_xxx() = - *y.get_u_xxx();
1018  *z.get_u_xxy() = - *y.get_u_xxy();
1019  *z.get_u_xyy() = - *y.get_u_xyy();
1020  *z.get_u_yyy() = - *y.get_u_yyy();
1021  return z;
1022  }
1023 
1029  double y)
1030  {
1031  df3_two_variable z;
1032  *z.get_u() = *x.get_u()-y;
1033  *z.get_u_x() = *x.get_u_x();
1034  *z.get_u_y() = *x.get_u_y();
1035  *z.get_u_xx() = *x.get_u_xx();
1036  *z.get_u_xy() = *x.get_u_xy();
1037  *z.get_u_yy() = *x.get_u_yy();
1038  *z.get_u_xxx() = *x.get_u_xxx();
1039  *z.get_u_xxy() = *x.get_u_xxy();
1040  *z.get_u_xyy() = *x.get_u_xyy();
1041  *z.get_u_yyy() = *x.get_u_yyy();
1042  return z;
1043  }
1044 
1050 {
1051  /*
1052  if (ind_var != 0)
1053  {
1054  cerr << " can only have 1 independent_variable in a reverse funnel"
1055  << endl;
1056  ad_exit(1);
1057  }
1058  */
1059  if (num_ind_var>1)
1060  {
1061  cerr << "can only have 2 independent_variables in df3_two_variable"
1062  " function" << endl;
1063  ad_exit(1);
1064  }
1065  else
1066  {
1068 
1069  ind_var[num_ind_var++]=&v;
1070  *get_u() = *v.get_u();
1071  switch(num_ind_var)
1072  {
1073  case 1:
1074  *get_u_x() = 1.0;
1075  *get_u_y() = 0.0;
1076  break;
1077  case 2:
1078  *get_u_x() = 0.0;
1079  *get_u_y() = 1.0;
1080  break;
1081  default:
1082  cerr << "illegal num_ind_var value of " << num_ind_var
1083  << " in df3_two_variable function" << endl;
1084  ad_exit(1);
1085  }
1086  *get_u_xx() = 0.0;
1087  *get_u_xy() = 0.0;
1088  *get_u_yy() = 0.0;
1089  *get_u_xxx() = 0.0;
1090  *get_u_xxy() = 0.0;
1091  *get_u_xyy() = 0.0;
1092  *get_u_yyy() = 0.0;
1093  }
1094 }
1095 
1101  {
1102  *get_u() = v;
1103  *get_u_x() = 0.0;
1104  *get_u_y() = 0.0;
1105  *get_u_xx() = 0.0;
1106  *get_u_xy() = 0.0;
1107  *get_u_yy() = 0.0;
1108  *get_u_xxx() = 0.0;
1109  *get_u_xxy() = 0.0;
1110  *get_u_xyy() = 0.0;
1111  *get_u_yyy() = 0.0;
1112  }
1113 
1115  {
1116  }
1117 
1123 {
1124  // kludge to deal with constantness
1125  df3_two_matrix & M= (df3_two_matrix &) MM;
1126  int rmin=M.indexmin();
1127  int cmin=M(rmin).indexmin();
1128  int rmax=M.indexmax();
1129  int cmax=M(rmin).indexmax();
1130  if (rmin !=1 || cmin !=1)
1131  {
1132  cerr << "minimum row and column inidices must equal 1 in "
1133  "df1b2matrix choleski_decomp(const df3_two_atrix& MM)"
1134  << endl;
1135  ad_exit(1);
1136  }
1137  if (rmax !=cmax)
1138  {
1139  cerr << "Error in df1b2matrix choleski_decomp(const df3_two_matrix& MM)"
1140  " Matrix not square" << endl;
1141  ad_exit(1);
1142  }
1143 
1144  int n=rmax-rmin+1;
1145  df3_two_matrix L(1,n,1,n);
1146 #ifndef SAFE_INITIALIZE
1147  L.initialize();
1148 #endif
1149 
1150  int i,j,k;
1151  df3_two_variable tmp;
1152 
1153  if (value(M(1,1))<=0)
1154  {
1155  cerr << "Error matrix not positive definite in choleski_decomp"
1156  <<endl;
1157  ad_exit(1);
1158  }
1159 
1160  L(1,1)=sqrt(M(1,1));
1161  for (i=2;i<=n;i++)
1162  {
1163  L(i,1)=M(i,1)/L(1,1);
1164  }
1165 
1166  for (i=2;i<=n;i++)
1167  {
1168  for (j=2;j<=i-1;j++)
1169  {
1170  tmp=M(i,j);
1171  for (k=1;k<=j-1;k++)
1172  {
1173  tmp-=L(i,k)*L(j,k);
1174  }
1175  L(i,j)=tmp/L(j,j);
1176  }
1177  tmp=M(i,i);
1178  for (k=1;k<=i-1;k++)
1179  {
1180  tmp-=L(i,k)*L(i,k);
1181  }
1182 
1183  if (value(tmp)<=0)
1184  {
1185  cerr << "Error matrix not positive definite in choleski_decomp"
1186  <<endl;
1187  ad_exit(1);
1188  }
1189 
1190  L(i,i)=sqrt(tmp);
1191  }
1192 
1193  return L;
1194 }
1195 
1201 {
1202  int rmin=M.indexmin();
1203  int rmax=M.indexmax();
1204  if (rmin != indexmin() || rmax != indexmax())
1205  {
1206  cerr << "unequal shape in "
1207  "df1b2matrix& df1b2matrix::operator = (const df3_two_matrix& M)"
1208  << endl;
1209  ad_exit(1);
1210  }
1211 
1212  for (int i=rmin;i<=rmax;i++)
1213  {
1214  (*this)(i)=M(i);
1215  }
1216  return *this;
1217 }
1218 
1224 {
1225  int rmin=M.indexmin();
1226  int rmax=M.indexmax();
1227  if (rmin != indexmin() || rmax != indexmax())
1228  {
1229  cerr << "unequal shape in "
1230  "df1b2vector& df1b2vector::operator = (const df3_two_vector& M)"
1231  << endl;
1232  ad_exit(1);
1233  }
1234 
1235  for (int i=rmin;i<=rmax;i++)
1236  {
1237  (*this)(i)=M(i);
1238  }
1239  return *this;
1240 }
1241 
1247 {
1248  df1b2variable * px=df3_two_variable::ind_var[0];
1249  df1b2variable * py=df3_two_variable::ind_var[1];
1251  df3_two_variable::ind_var[0]=0;
1252  df3_two_variable::ind_var[1]=0;
1253  //df1b2variable * px=0;
1254  double dfx= *v.get_u_x();
1255  double dfy= *v.get_u_y();
1256  double * xd=px->get_u_dot();
1257  double * yd=py->get_u_dot();
1258  double * zd=get_u_dot();
1259  *get_u()=*v.get_u();
1260  for (unsigned int i=0;i<df1b2variable::nvar;i++)
1261  {
1262  *zd++ = dfx * *xd++ + dfy * *yd++;
1263  }
1264 
1265  f1b2gradlist->write_pass1(px,py,this,
1266  *v.get_u_x(),
1267  *v.get_u_y(),
1268  *v.get_u_xx(),
1269  *v.get_u_xy(),
1270  *v.get_u_yy(),
1271  *v.get_u_xxx(),
1272  *v.get_u_xxy(),
1273  *v.get_u_xyy(),
1274  *v.get_u_yyy());
1275  return *this;
1276 }
1277 
1283 {
1284  df1b2variable z;
1285  double xu=*x.get_u();
1286  double yu=*y.get_u();
1287  double yinv=1.0/yu;
1288  *z.get_u()=xu*yinv;
1289 
1290  double dfx= yinv;
1291  double dfy= -xu*yinv*yinv;
1292  double dfxx= 0.0;
1293  double dfxy=-yinv*yinv;
1294  double dfyy=2.0*xu*yinv*yinv*yinv;
1295  double dfxxx= 0.0;
1296  double dfxxy= 0.0;
1297  double dfxyy=2.0*yinv*yinv*yinv;
1298  double dfyyy=-6.0*xu*yinv*yinv*yinv*yinv;
1299 
1300  double * xd=x.get_u_dot();
1301  double * yd=y.get_u_dot();
1302  double * zd=z.get_u_dot();
1303 
1304  for (unsigned int i=0;i<df1b2variable::nvar;i++)
1305  {
1306  *zd++ = dfx * *xd++ + dfy * *yd++;
1307  }
1308 
1309  f1b2gradlist->write_pass1(&x,&y,&z,
1310  dfx,
1311  dfy,
1312  dfxx,dfxy,dfyy,
1313  dfxxx,dfxxy,dfxyy,dfyyy);
1314  return z;
1315 }
1316 
1322 {
1323  df1b2variable z;
1324  double xu=*x.get_u();
1325  *z.get_u()=::pow(xu,y);
1326 
1327  double dfx= y*::pow(xu,y-1.0);
1328  double dfxx= y*(y-1.0)*::pow(xu,y-2.0);
1329  double dfxxx= y*(y-1.0)*(y-2.0)*::pow(xu,y-3.0);
1330  double * xd=x.get_u_dot();
1331  double * zd=z.get_u_dot();
1332 
1333  for (unsigned int i=0;i<df1b2variable::nvar;i++)
1334  {
1335  *zd++ = dfx * *xd++ ;
1336  }
1337 
1338  f1b2gradlist->write_pass1(&x,&z,
1339  dfx,
1340  dfxx,
1341  dfxxx);
1342  return z;
1343 }
d3_array tan(const d3_array &arr3)
Returns d3_array results with computed tan from elements in arr3.
Definition: d3arr2a.cpp:73
~df3_two_vector()
Destructor.
Definition: df32fun.cpp:49
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
void * trueptr
Address of first element in the vector.
Definition: vector_shapex.h:82
Description not yet available.
Definition: fvar.hpp:2030
double * get_u_xy(void) const
Definition: df32fun.h:82
void allocate(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat0.cpp:8
df1b2variable & operator=(const df3_one_variable &v)
Definition: df3fun.cpp:779
double * get_u() const
Definition: df1b2fun.h:228
Description not yet available.
Definition: df32fun.h:55
d3_array operator-(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements addition of a(i, j, k) + b(i, j, k).
Definition: d3arr2a.cpp:152
#define x
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin(void) const
Definition: df1b2fun.h:1054
void initialize(void)
Initialize df3_two_vector to zero.
Definition: df32fun.cpp:91
Description not yet available.
Definition: df1b2fun.h:953
d3_array operator+(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements addition of a(i, j, k) + b(i, j, k).
Definition: d3arr2a.cpp:132
df1_one_variable atan(const df1_one_variable &x)
Definition: df11fun.cpp:312
d3_array sin(const d3_array &arr3)
Returns d3_array results with computed sin from elements in arr3.
Definition: d3arr2a.cpp:43
double v[10]
Definition: df32fun.h:57
df1_two_variable fabs(const df1_two_variable &x)
Definition: df12fun.cpp:891
exitptr ad_exit
Definition: gradstrc.cpp:53
void set_derivatives(df1_one_variable &z, const df1_one_variable &x, double u, double zp)
Definition: df11fun.cpp:280
double * get_u(void) const
Definition: df32fun.h:66
int indexmin(void) const
Definition: df1b2fun.h:969
d3_array cube(const d3_array &m)
Description not yet available.
Definition: d3arr5.cpp:17
int indexmax(void) const
Definition: df32fun.h:199
int operator<(double v0, const prevariable &v1)
Description not yet available.
Definition: compare.cpp:53
df3_two_vector(void)
Default constructor.
Definition: df32fun.cpp:103
df3_two_variable & operator*=(const df3_two_variable &v)
Multiply df3_two_variable and v which calls set_derivatives.
Definition: df32fun.cpp:340
Description not yet available.
Definition: df1b2fun.h:266
df1b2matrix & operator=(const df3_one_matrix &)
Definition: df3fun.cpp:741
df1_one_matrix choleski_decomp(const df1_one_matrix &MM)
Definition: df11fun.cpp:606
dmatrix operator*(const d3_array &t, const dvector &v)
Description not yet available.
Definition: d3arr12.cpp:17
double * get_u_y(void) const
Definition: df32fun.h:74
int operator==(double v0, const prevariable &v1)
Description not yet available.
Definition: compare.cpp:17
double * get_u_xx(void) const
Definition: df32fun.h:78
double * get_u_dot() const
Definition: df1b2fun.h:229
double * get_u_x(void) const
Definition: df32fun.h:70
void * get_pointer(void)
Definition: fvar.hpp:2046
void allocate(void)
Does NOT allocate, but initializes empty df3_two_vector.
Definition: df32fun.cpp:145
vector_shapex * shape
Definition: df32fun.h:145
double * get_u_xyy(void) const
Definition: df32fun.h:98
df1b2vector & operator=(const df3_one_vector &)
Definition: df3fun.cpp:760
int indexmin(void) const
Definition: df32fun.h:148
prnstream & endl(prnstream &)
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2c.cpp:11
df3_two_variable & operator=(const df3_two_variable &v)
Description not yet available.
Definition: df32fun.cpp:784
#define min(a, b)
Definition: cbivnorm.cpp:188
static df1b2variable * ind_var[]
Definition: df32fun.h:60
df3_two_variable & operator+=(const df3_two_variable &v)
Add values from _v to df3_two_variable.
Definition: df32fun.cpp:305
double * get_u_xxy(void) const
Definition: df32fun.h:94
int indexmax(void) const
Definition: df32fun.h:152
Description not yet available.
Definition: df32fun.h:188
double * get_u_yyy(void) const
Definition: df32fun.h:102
~df3_two_matrix()
Destructor.
Definition: df32fun.cpp:191
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
df1b2variable mypow(const df1b2variable &x, double y)
Description not yet available.
Definition: df32fun.cpp:1321
#define M
Definition: rngen.cpp:57
df3_two_variable & operator-=(double v)
Subtract value _v from only df3_two_variable u with the rest of the values unchanged.
Definition: df32fun.cpp:332
void initialize(void)
Description not yet available.
Definition: df32fun.cpp:221
Description not yet available.
Definition: fvar.hpp:2819
df3_two_matrix(int rmin, int rmax, int cmin, int cmax)
Construct matrix of df3_two_variable with dimension [rmin to rmax] x [cmin to cmax].
Definition: df32fun.cpp:240
unsigned int ncopies
Copy counter to enable shallow copies.
Definition: vector_shapex.h:79
double * get_u_yy(void) const
Definition: df32fun.h:86
unsigned int ncopies
Definition: fvar.hpp:2034
int write_pass1(const df1b2variable *px, const df1b2variable *py, df1b2variable *pz, df1b2function2 *pf)
Description not yet available.
Definition: df1b2f12.cpp:17
Holds &quot;shape&quot; information for vector objects.
Definition: vector_shapex.h:46
d3_array cos(const d3_array &arr3)
Returns d3_array results with computed cos from elements in arr3.
Definition: d3arr2a.cpp:58
Description not yet available.
Definition: df1b2fun.h:1042
int operator>(double v0, const prevariable &v1)
Description not yet available.
Definition: compare.cpp:44
df3_two_vector * v
Definition: df32fun.h:193
static unsigned int nvar
Definition: df1b2fun.h:290
int indexmin(void) const
Definition: df32fun.h:195
#define w
Description not yet available.
Definition: df32fun.h:141
int indexmax(void) const
Definition: df1b2fun.h:970
int indexmax(void) const
Definition: df1b2fun.h:1055
Description not yet available.
df3_two_variable * v
Definition: df32fun.h:146
mat_shapex * shape
Definition: df32fun.h:192
d3_array operator/(const d3_array &m, const double d)
Author: David Fournier.
Definition: d3arr2b.cpp:14
init_df3_two_variable(const df1b2variable &)
Description not yet available.
Definition: df32fun.cpp:1049
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
#define max(a, b)
Definition: cbivnorm.cpp:189
static int num_ind_var
Definition: df32fun.h:61
void deallocate(void)
Deallocate df3_two_vector, then set to empty.
Definition: df32fun.cpp:196
void deallocate(void)
Deallocate df3_two_vector, then set to empty.
Definition: df32fun.cpp:54
df3_two_variable & operator/=(const df3_two_variable &v)
Description not yet available.
Definition: df32fun.cpp:369
int operator>=(double v0, const prevariable &v1)
Description not yet available.
Definition: compare.cpp:35
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
df1_one_variable inv(const df1_one_variable &x)
Definition: df11fun.cpp:384
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13
double * get_u_xxx(void) const
Definition: df32fun.h:90
df1b2variable div(const df1b2variable &x, const df1b2variable &y)
Description not yet available.
Definition: df32fun.cpp:1282
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17