Revision 1250

trunk/tests/gtests/df1b2atan2.cpp (revision 1250)
1
/*
2
$Id$
3

  
4
Author: David Fournier
5
Copyright (c) 2013 ADMB Foundation
6
*/
7
#include <df1b2fun.h>
8

  
9
/**
10
Computes arc tangent with df1b2variables y and x. 
11

  
12
\param y y-coordinate
13
\param x x-coordinate
14
\return Return arc tangent value in radians. 
15
*/
16
df1b2variable atan2(const df1b2variable& y, const df1b2variable& x)
17
{
18
  df1b2variable z;
19
  double xu=*x.get_u();
20
  double yu=*y.get_u();
21
  double r2=square(xu)+square(yu);
22
  double zu=::atan2(yu,xu);
23
  *z.get_u()=zu;
24

  
25
  double dfx=-yu/r2;
26
  double dfy=xu/r2;
27
  double dfxx=2.0*yu*xu/square(r2);
28
  double dfxy=-1.0/r2+2.0*square(yu)/square(r2);
29
  double dfyy=-2.0*xu*yu/square(r2);
30
  double dfxxx=2.0*yu/square(r2)-8.0*yu*square(xu)/cube(r2);
31
  double dfxxy=2.0*xu/square(r2)-8.0*square(yu)*xu/cube(r2);
32
  double dfxyy=-2.0*yu/square(r2)+8.0*square(xu)*yu/cube(r2);
33
  double dfyyy=-2.0*xu/square(r2)+8.0*xu*square(yu)/cube(r2);
34

  
35
  double* xd=x.get_u_dot();
36
  double* yd=y.get_u_dot();
37
  double* zd=z.get_u_dot();
38

  
39
  for (int i=0;i<df1b2variable::nvar;i++)
40
  {
41
    *zd++ = dfx * (*xd++) + dfy * (*yd++);
42
  }
43

  
44
  f1b2gradlist->write_pass1(&y,&x,&z,
45
      dfy,
46
      dfx,
47
      dfyy,dfxy,dfxx,
48
      dfyyy,dfxyy,dfxxy,dfxxx);
49

  
50
  return z;
51
}

Also available in: Unified diff