example_ad_double

View page source

An Example Using the ad_double Class

This example mixes the documentation and the example code. Another choice is to put the documentation and the beginning an then just have comments in the code.

xrst_indent

This example make uses of xrst_indent so that the xrst input can be indented at the same level as the code it is next to.

Begin Function

This function has no arguments and returns a boolean that is true, if all it’s tests pass, and false otherwise.

bool test_ad_double(void)
{

Initialize ok

   bool ok = true;

Independent Variable

   double x  = 2.0;
   double dx = 3.0;
   ad_double ax(x, dx);

Addition

   {  ad_double ay = ax + ax;
      double    dy = ay.derivative();
      ok          &= dy == 2.0 * dx;
   }

Subtraction

   {  ad_double ay = ax - ax;
      double    dy = ay.derivative();
      ok          &= dy == 0.0;
   }

Multiplication

   {  ad_double ay = ax * ax;
      double    dy = ay.derivative();
      ok          &= dy == 2.0 * x * dx;
   }

Division

   {  ad_double ay = ax / ax;
      double    dy = ay.derivative();
      ok          &= dy == 0.0;
   }

Return ok

   return ok;
}

Example File

This Example File is the same as for the parent of this page.