Prev | Next | multi_chkpoint_one_algo |
checkpoint_algo(au, ay)
const ADvector& au
where
ADvector
is a
simple vector class
with elements
of type AD<double>
.
The size of
au
is three.
y_initial = au[0]
for the initial value of the Newton iterate.
y_squared = au[1]
for the value we are taking the square root of.
ADvector& ay
The size of
ay
is one and
ay[0]
is the square root of
y_squared
.
// includes used by all source code in multi_chkpoint_one.cpp file # include <cppad/cppad.hpp> # include "multi_chkpoint_one.hpp" # include "team_thread.hpp" // namespace { using CppAD::thread_alloc; // fast multi-threading memory allocator using CppAD::vector; // uses thread_alloc // typedef CppAD::AD<double> a_double; void checkpoint_algo(const vector<a_double>& au , vector<a_double>& ay) { // extract components of argument vector a_double y_initial = au[0]; a_double y_squared = au[1]; // Use Newton's method to solve f(y) = y^2 = y_squared a_double y_itr = y_initial; for(size_t itr = 0; itr < 20; itr++) { // solve (y - y_itr) * f'(y_itr) = y_squared - y_itr^2 a_double fp_itr = 2.0 * y_itr; y_itr = y_itr + (y_squared - y_itr * y_itr) / fp_itr; } // return the Newton approximation for f(y) = y_squared ay[0] = y_itr; } }