<?xml version='1.0'?> <?xml-stylesheet type='text/xsl' href='pmathml.xsl'?> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>ODE Inverse Problem Definitions: Source Code</title> <meta name="description" id="description" content="ODE Inverse Problem Definitions: Source Code"/> <meta name="keywords" id="keywords" content=" ode inverse example "/> <style type='text/css'> body { color : black } body { background-color : white } A:link { color : blue } A:visited { color : purple } A:active { color : purple } </style> <script type='text/javascript' language='JavaScript' src='_ipopt_ode_problem.hpp_xml.js'> </script> </head> <body> <table><tr> <td> <a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a> </td> <td><a href="ipopt_ode_problem.xml" target="_top">Prev</a> </td><td><a href="ipopt_ode_simple.xml" target="_top">Next</a> </td><td> <select onchange='choose_across0(this)'> <option>Index-></option> <option>contents</option> <option>reference</option> <option>index</option> <option>search</option> <option>external</option> </select> </td> <td> <select onchange='choose_up0(this)'> <option>Up-></option> <option>CppAD</option> <option>Example</option> <option>General</option> <option>ipopt_cppad_nlp</option> <option>ipopt_cppad_ode</option> <option>ipopt_ode_problem</option> <option>ipopt_ode_problem.hpp</option> </select> </td> <td> <select onchange='choose_down3(this)'> <option>ipopt_cppad_nlp-></option> <option>ipopt_cppad_windows</option> <option>ipopt_get_started.cpp</option> <option>ipopt_cppad_ode</option> </select> </td> <td> <select onchange='choose_down2(this)'> <option>ipopt_cppad_ode-></option> <option>ipopt_ode_problem</option> <option>ipopt_ode_simple</option> <option>ipopt_ode_fast</option> <option>ipopt_ode_run.hpp</option> <option>ipopt_ode_check.cpp</option> <option>ipopt_ode_speed.cpp</option> </select> </td> <td> <select onchange='choose_down1(this)'> <option>ipopt_ode_problem-></option> <option>ipopt_ode_problem.hpp</option> </select> </td> <td>ipopt_ode_problem.hpp</td> <td>Headings</td> </tr></table><br/> <center><b><big><big>ODE Inverse Problem Definitions: Source Code</big></big></b></center> <code><font color="blue"><pre style='display:inline'> # include "ipopt_cppad_nlp.hpp" namespace { //------------------------------------------------------------------ typedef Ipopt::Number Number; Number a0 = 1.; // simulation value for a[0] Number a1 = 2.; // simulation value for a[1] Number a2 = 1.; // simulatioln value for a[2] // function used to simulate data Number y_one(Number t) { Number y_1 = a0*a1 * (exp(-a2*t) - exp(-a1*t)) / (a1 - a2); return y_1; } // time points were we have data (no data at first point) double s[] = { 0.0, 0.5, 1.0, 1.5, 2.0 }; // Simulated data for case with no noise (first point is not used) double z[] = { 0.0, y_one(0.5), y_one(1.0), y_one(1.5), y_one(2.0) }; // Number of measurement values size_t Nz = sizeof(z) / sizeof(z[0]) - 1; // Number of components in the function y(t, a) size_t Ny = 2; // Number of components in the vectro a size_t Na = 3; // Initial Condition function, F(a) = y(t, a) at t = 0 // (for this particular example) template <class Vector> Vector eval_F(const Vector &a) { Vector F(Ny); // y_0 (t) = a[0]*exp(-a[1] * t) F[0] = a[0]; // y_1 (t) = // a[0]*a[1]*(exp(-a[2] * t) - exp(-a[1] * t))/(a[1] - a[2]) F[1] = 0.; return F; } // G(y, a) = \partial_t y(t, a); i.e. the differential equation // (for this particular example) template <class Vector> Vector eval_G(const Vector &y , const Vector &a) { Vector G(Ny); // y_0 (t) = a[0]*exp(-a[1] * t) G[0] = -a[1] * y[0]; // y_1 (t) = // a[0]*a[1]*(exp(-a[2] * t) - exp(-a[1] * t))/(a[1] - a[2]) G[1] = +a[1] * y[0] - a[2] * y[1]; return G; } // H(i, y, a) = contribution to objective at i-th data point // (for this particular example) template <class Scalar, class Vector> Scalar eval_H(size_t i, const Vector &y, const Vector &a) { // This particular H is for a case where y_1 (t) is measured Scalar diff = z[i] - y[1]; return diff * diff; } }</pre> </font></code> <hr/>Input File: ipopt_cppad/ipopt_ode_problem.hpp </body> </html>