checkpoint_algo(au, ay)
const ADvector& au
ADvector
AD<double>
au
y_initial = au[0]
y_squared = au[1]
ADvector& ay
ay
ay[0]
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; } }