\(\newcommand{\W}[1]{ \; #1 \; }\) \(\newcommand{\R}[1]{ {\rm #1} }\) \(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }\) \(\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }\) \(\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }\) \(\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }\)
exp_2¶
View page sourceSecond Order Exponential Approximation¶
Syntax¶
include
"exp_2.hpp"
exp_2
( x )Purpose¶
This is a simple example algorithm that is used to demonstrate Algorithmic Differentiation (see exp_eps for a more complex example).
Mathematical Form¶
The exponential function can be defined by
The second order approximation for the exponential function is
include¶
The include command in the syntax is relative to
cppad-
yyyymmdd /introduction/exp_apx
where cppad-
yyyymmdd is the distribution directory
created during the beginning steps of the
installation of CppAD.
x¶
The argument x has prototype
const
Type & x
(see Type below). It specifies the point at which to evaluate the approximation for the second order exponential approximation.
y¶
The result y has prototype
Type y
It is the value of the exponential function approximation defined above.
Type¶
If u and v are Type objects and i
is an int
:
Operation |
Result Type |
Description |
Type ( i ) |
Type |
construct object with value equal to i |
Type u = v |
Type |
construct u with value equal to v |
u * v |
Type |
result is value of \(u * v\) |
u / v |
Type |
result is value of \(u / v\) |
u + v |
Type |
result is value of \(u + v\) |
Contents¶
Name |
Title |
---|---|
exp_2.hpp |
|
exp_2.cpp |
|
exp_2_for0 |
|
exp_2_for1 |
|
exp_2_rev1 |
|
exp_2_for2 |
|
exp_2_rev2 |
|
exp_2_cppad |
Implementation¶
The file exp_2.hpp contains a C++ implementation of this function.
Test¶
The file exp_2.cpp contains a test of this implementation.
Exercises¶
Suppose that we make the call
double x = .1; double y = exp_2(x);
What is the value assigned to
v1
,v2
, … ,``v5`` in exp_2.hpp ?Extend the routine
exp_2.hpp
to a routineexp_3.hpp
that computes\[1 + x^2 / 2 ! + x^3 / 3 !\]Do this in a way that only assigns one value to each variable (as
exp_2
does).Suppose that we make the call
double x = .5; double y = exp_3(x);
using
exp_3
created in the previous problem. What is the value assigned to the new variables inexp_3
(variables that are inexp_3
and not inexp_2
) ?