source: trunk/ADOL-C/examples/additional_examples/taylor/coordinates.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: 3.5 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     coordinates.cpp
4 Revision: $Id: coordinates.cpp 42 2009-07-15 18:37:17Z awalther $
5 Contents: Test driver 'inverse_tensor_eval' using transformation between
6           Cartesian coordinates and polar coordinates
7 
8 Copyright (c) Andrea Walther, Andreas Griewank
9
10 This file is part of ADOL-C. This software is provided as open source.
11 Any use, reproduction, or distribution of the software constitutes
12 recipient's acceptance of the terms of the accompanying license file.
13 
14---------------------------------------------------------------------------*/
15
16/****************************************************************************/
17/*                                                                 INCLUDES */
18#include <adolc.h>
19
20#include <cstdlib>
21#include <iostream>
22using namespace std;
23
24/****************************************************************************/
25/*                                                                     MAIN */
26int main() {
27    int i,j,n,d,p,dim;
28    double zp[4];
29    double gp[2];
30    double zd[2];
31
32    /*--------------------------------------------------------------------------*/
33    cout << "COORDINATES (ADOL-C Example)\n\n";                     /* inputs */
34    cout << " Cartesian coordinates:\n";
35    cout << " z_1: (e.g. 4) \n";
36    cin >> zp[0];
37    cout << " z_2: (e.g. 3) \n";
38    cin >> zp[1];
39    cout << "\n Polar coordinates:\n";
40    cout << " z_3: (e.g. 5) \n";
41    cin >> zp[2];
42    cout << " z_4: (e.g. 0.64350110879) \n";
43    cin >> zp[3];
44
45    cout << "\n Highest derivative degree = 3\n";
46
47    /*--------------------------------------------------------------------------*/
48    /* allocations and inits */
49    n = 4;
50    p = 2;
51    d = 3;
52
53    double** S = new double*[n];
54    double** tensor = new double*[n];
55    double**** tensorentry;
56
57    for (i=0; i<n; i++) {
58        S[i] = new double[p];
59        for(j=0;j<p;j++)
60            S[i][j]=0.0;
61    }
62    S[2][0] = 1;
63    S[3][1] = 1;
64
65    /*--------------------------------------------------------------------------*/
66    trace_on(1);                                      /* tracing the function */
67    adouble* z = new adouble[n];
68    adouble* g = new adouble[2];
69
70    for(i=0;i<n;i++)
71        z[i] <<= zp[i];
72    g[0] = z[0]*z[0] + z[1]*z[1] - z[2]*z[2];
73    g[1] = cos(z[3]) - z[0]/z[2];
74    g[0] >>= gp[0];
75    g[1] >>= gp[1];
76    z[0] >>= zd[0];
77    z[2] >>= zd[1];
78    trace_off();
79
80    /*--------------------------------------------------------------------------*/
81    dim = binomi(p+d,d);                               /* inverse_tensor_eval */
82    for(i=0;i<n;i++) {
83        tensor[i] = new double[dim];
84        for(j=0;j<dim;j++)
85            tensor[i][j] = 0;
86    }
87    inverse_tensor_eval(1,n,d,p,zp,tensor,S);
88    tensorentry = (double****) tensorsetup(n,p,d,tensor);
89    cout<< "\n Some partial derivatives: \n\n";
90    cout <<"     Tensor";
91    cout << "[1][1][0][0]: \t";
92    cout << tensorentry[1][1][0][0] << "\n\n";
93    cout <<"     Tensor";
94    cout << "[1][2][0][0]: \t";
95    cout << tensorentry[1][2][0][0] << "\n\n";
96    cout <<"     Tensor";
97    cout << "[1][2][1][0]: \t";
98    cout << tensorentry[1][2][1][0] << "\n\n";
99    free((char*) *tensor);
100    free((char*)tensor);
101    freetensor(n,p,d, (double **) tensorentry);
102
103    return 1;
104}
105
106/****************************************************************************/
107/*                                                               THAT'S ALL */
Note: See TracBrowser for help on using the repository browser.