Created
January 13, 2020 08:23
-
-
Save mickeyouyou/9558afbc7267f4953509f8cb241db41b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*---------------------------------------------------------------------------- | |
ADOL-C -- Automatic Differentiation by Overloading in C++ | |
File: tapeless_scalar.cpp | |
Revision: $Id$ | |
Contents: computation of coordinate transform, | |
scalar tapeless forward mode | |
described in the manual | |
Copyright (c) Andrea Walther, Andreas Kowarz | |
This file is part of ADOL-C. This software is provided as open source. | |
Any use, reproduction, or distribution of the software constitutes | |
recipient's acceptance of the terms of the accompanying license file. | |
---------------------------------------------------------------------------*/ | |
/****************************************************************************/ | |
/* INCLUDES */ | |
#include <iostream> | |
// #include "adolc/adouble.h" | |
#include "adolc/adtl.h" | |
using namespace std; | |
typedef adtl::adouble adouble; | |
#define NUMBER_DIRECTIONS 3 | |
#define ADOLC_TAPELESS | |
ADOLC_TAPELESS_UNIQUE_INTERNALS; | |
int main(int argc, char *argv[]) { | |
adtl::adouble x[3], y[3]; | |
for (int i = 0; i < 3; ++i) { | |
// Initialize x i | |
x[i] = i + 1.0; | |
for (int j = 0; j < 3; ++j) { | |
if (i == j) { | |
x[i].setADValue(j, 1); | |
} | |
} | |
} | |
y[0] = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); | |
y[1] = atan(sqrt(x[0] * x[0] + x[1] * x[1]) / x[2]); | |
y[2] = atan(x[1] / x[0]); | |
cout << "y1= " << y[0].getValue() << "y2= " << y[1].getValue() << endl; | |
cout << "Jacobian:" << endl; | |
for (int i = 0; i < 3; i++) { | |
for (int j = 0; j < 3; j++) { | |
cout << y[i].getADValue(j) << " "; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment