source: trunk/ADOL-C/examples/tapeless_scalar.cpp @ 42

Last change on this file since 42 was 42, checked in by awalther, 10 years ago

set svn keywords property

  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     tapeless_scalar.cpp
4 Revision: $Id: tapeless_scalar.cpp 42 2009-07-15 18:37:17Z awalther $
5 Contents: computation of coordinate transform,
6           scalar tapeless forward mode
7           described in the manual
8
9 Copyright (c) Andrea Walther, Andreas Kowarz
10 
11 This file is part of ADOL-C. This software is provided as open source.
12 Any use, reproduction, or distribution of the software constitutes
13 recipient's acceptance of the terms of the accompanying license file.
14 
15---------------------------------------------------------------------------*/
16
17
18/****************************************************************************/
19/*                                                                 INCLUDES */
20
21#include <iostream>
22using namespace std;
23
24#define ADOLC_TAPELESS
25#include <adouble.h>
26typedef adtl::adouble adouble;
27
28
29int main(int argc, char *argv[]) {
30    adouble x[3], y[3];
31
32    for (int i=0; i<3;++i)          // Initialize x_i
33        x[i] = i + 1.0;
34
35    cout << endl << "Compute transform from Cartesian to spherical polar coordinates" << endl << endl;
36
37    // derivative of y with respect to x0
38    x[0].setADValue(1);
39
40    y[0] = sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);
41    y[1] = atan(sqrt(x[0]*x[0]+x[1]*x[1])/x[2]);
42    y[2] = atan(x[1]/x[0]);
43
44    cout << "cartesian coordinates: " << endl;
45    cout << "x[0] = " << x[0].getValue() << "  x[1] = " << x[1].getValue()
46    << "  x[2] = " << x[2].getValue() << endl << endl;
47    cout << "cpherical polar coordinates: " << endl;
48    cout << "y[0] = " << y[0].getValue() << "  y[1] = " << y[1].getValue()
49    << "  y[2] = " << y[2].getValue() << endl <<endl;
50
51    // "use" the derivative
52    cout << "derivative:" << endl;
53    cout << "dy[0]/dx[0] = " << y[0].getADValue() << "  dy[1]/dx[0] = " << y[1].getADValue()
54    << "  dy[2]/dx[0] = " << y[2].getADValue() << endl;
55
56    return 0;
57}
58
Note: See TracBrowser for help on using the repository browser.