source: trunk/ADOL-C/examples/additional_examples/taylor/trigger.cpp @ 171

Last change on this file since 171 was 171, checked in by kulshres, 9 years ago

Squashed merge branch 'master' of 'gitclone' into svn

  • 'master' of 'gitclone': (84 commits) adjust example makefiles and include paths get rid of the symlink in the src subdirectory

details of the commits:
commit c9e4bc332d2363f737fc2e8a8fcfc2e43ddb9d15
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:43:47 2010 +0200

adjust example makefiles and include paths

include paths in example sources were wrong for some time now
simplify makefile rules too, there is really no need for checking SPARSE
adjust include paths in makefiles.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e6e1963e41e097fd5b4a79cd1611c12f6868dc94
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:41:25 2010 +0200

get rid of the symlink in the src subdirectory

windows doesn't like symlinks and make infinite depth directories
we now create a symlink for build in the directory parallel to src
adjust all makefiles.am accordingly for build

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     trigger.cpp
4 Revision: $Id: trigger.cpp 171 2010-10-04 13:57:19Z kulshres $
5 Contents:  Test driver 'inverse_tensor_eval(..)' that allows to
6            compute higher order derivatives of inverse functions
7           
8            Function model: trigger circuit
9 
10 Copyright (c) Andrea Walther, Andreas Griewank
11 
12 This file is part of ADOL-C. This software is provided as open source.
13 Any use, reproduction, or distribution of the software constitutes
14 recipient's acceptance of the terms of the accompanying license file.
15 
16---------------------------------------------------------------------------*/
17
18/****************************************************************************/
19/*                                                                 INCLUDES */
20#include <adolc/adolc.h>
21
22#include <cstdlib>
23
24
25/****************************************************************************/
26/*                                                                     MAIN */
27int main() {
28    int i,j,n,d,p,dim;
29
30    /*--------------------------------------------------------------------------*/
31    printf(" TRIGGER CIRCUIT EXAMPLE (ADOL-C Example)\n\n");        /* inputs */
32    printf(" # of indeps = 7, # of deps = 7  (fixed)\n");
33
34    n = 7;
35    p = 3;
36    d = 4;
37
38    /*--------------------------------------------------------------------------*/
39    double* xp = new double[n];                      /* allocations and inits */
40    double* Fhp = new double[n];
41    double** S = new double*[n];
42    double** tensoren;
43    int* multi = new int[d];
44    int* add = new int[5];
45
46    for(i=0;i<n;i++) {
47        S[i] = new double[p];
48        for(j=0;j<p;j++)
49            S[i][j] = 0;
50    }
51    S[4][0] = 1;
52    S[5][1] = 1;
53    S[6][2] = 1;
54
55    xp[0] = 5.155103392445;
56    xp[1] = 5.808134401609;
57    xp[2] = 5.764511314735;
58    xp[3] = 5.569172054801;
59    xp[4] = 5.786953999546;
60    xp[5] = 1.1294023667;
61    xp[6] = 0;
62
63    /*--------------------------------------------------------------------------*/
64    trace_on(1);                                      /* tracing the function */
65    adouble* x = new adouble[n];
66    adouble* Fh = new adouble[n];
67
68    for(i=0;i<n;i++)
69        x[i] <<= xp[i];
70
71    Fh[0]=x[0]/20-1e-9*(exp(30*(x[4]-x[0]))+exp(30*(x[2]-x[0])))-1.88e-7;
72    Fh[0]+=+.95e-7*(exp(30*(x[4]-x[1]))+exp(30*(x[2]-x[3])));
73    Fh[1]= .99e-9*exp(30*(x[4]-x[0]))-1e-7*exp(30*(x[4]-x[1]))+.9901e-7;
74    Fh[1]+=+(x[1]-x[2])/50-(6-x[1])/x[5]-x[6];
75    Fh[2]= 1e-11*exp(30*(x[2]-x[0]))+5e-9*exp(30*(x[2]-x[3]))-5.01e-9;
76    Fh[2]+=-(x[1]-x[2])/50;
77    Fh[3]=.99e-9*exp(30*(x[2]-x[0]))-1e-7*exp(30*(x[2]-x[3]))+.9901e-7;
78    Fh[3]+=-(6-x[3])/5;
79    Fh[4]= x[0]-5.155103392445;
80    Fh[5]= x[4]-5.786953999546;
81    Fh[6] = x[5]-1.1294023667;
82
83    for(i=0;i<n;i++)
84        Fh[i] >>= Fhp[i];
85    trace_off();
86
87    /*--------------------------------------------------------------------------*/
88    printf("\n  Fh(x,0) = \n (");                      /* inverse_tensor_eval */
89    for(i=0;i<n;i++)
90        printf(" %f",Fhp[i]);
91    printf(" %15.10f )\n\n",Fhp[n-1]);
92    dim = binomi(p+d,d);
93    tensoren = myalloc2(n,dim);
94
95    inverse_tensor_eval(1,n,d,p,xp,tensoren,S);
96
97    for(i=0;i<d;i++)
98        multi[i] = 0;
99    multi[d-1] = 1;
100    add[0] = address(d,multi);
101    multi[d-2] = 1;
102    add[1] = address(d,multi);
103    multi[d-3] = 1;
104    add[2] = address(d,multi);
105    multi[d-1] = 2;
106    multi[d-2] = 0;
107    multi[d-3] = 0;
108    add[3] = address(d,multi);
109    multi[d-1] = 3;
110    add[4] = address(d,multi);
111    printf(" Results: \n");
112    printf(" Fh^{-1}(0,z) = \n (");
113    for(i=0;i<n-1;i++)
114        printf(" %15.10f ,",tensoren[i][0]);
115    printf(" %15.10f )\n\n",tensoren[n-1][0]);
116    printf(" Fh^{-1}_{z_1}(0,z) = \n (");
117    for(i=0;i<n-1;i++)
118        printf(" %15.10f ,",tensoren[i][add[0]]);
119    printf(" %15.10f )\n\n",tensoren[n-1][add[0]]);
120    printf(" Fh^{-1}_{x_1 x_1}(0,z) = \n (");
121    for(i=0;i<n-1;i++)
122        printf(" %15.10f ,",tensoren[i][add[1]]);
123    printf(" %15.10f )\n\n",tensoren[n-1][add[1]]);
124    printf(" Fh^{-1}_{x_1 x_1 x_1}(0,z) = \n (");
125    for(i=0;i<n-1;i++)
126        printf(" %15.10f ,",tensoren[i][add[2]]);
127    printf(" %15.10f )\n\n",tensoren[n-1][add[2]]);
128    printf(" Fh^{-1}_{x_2}(0,z) = \n (");
129    for(i=0;i<n-1;i++)
130        printf(" %15.10f ,",tensoren[i][add[3]]);
131    printf(" %15.10f )\n\n",tensoren[n-1][add[3]]);
132    printf(" Fh^{-1}_{x_3}(0,z) = \n (");
133    for(i=0;i<n-1;i++)
134        printf(" %15.10f ,",tensoren[i][add[4]]);
135    printf(" %15.10f )\n",tensoren[n-1][add[4]]);
136
137    return 1;
138}
139
140/****************************************************************************/
141/*                                                               THAT'S ALL */
142
143
Note: See TracBrowser for help on using the repository browser.