CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
det_33.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_SPEED_DET_33_HPP
2 # define CPPAD_SPEED_DET_33_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 /*
15 $begin det_33$$
16 $spell
17  cppad
18  CppAD
19  det
20  namespace
21  const
22  bool
23  hpp
24 $$
25 
26 $section Check Determinant of 3 by 3 matrix$$
27 $mindex det_33 correct$$
28 
29 
30 $head Syntax$$
31 $codei%# include <cppad/speed/det_33.hpp>
32 %$$
33 $icode%ok% = det_33(%x%, %d%)%$$
34 
35 $head Purpose$$
36 This routine can be used to check a method for computing
37 the determinant of a matrix.
38 
39 $head Inclusion$$
40 The template function $code det_33$$ is defined in the $code CppAD$$
41 namespace by including
42 the file $code cppad/speed/det_33.hpp$$
43 (relative to the CppAD distribution directory).
44 
45 $head x$$
46 The argument $icode x$$ has prototype
47 $codei%
48  const %Vector% &%x%
49 %$$.
50 It contains the elements of the matrix $latex X$$ in row major order; i.e.,
51 $latex \[
52  X_{i,j} = x [ i * 3 + j ]
53 \] $$
54 
55 $head d$$
56 The argument $icode d$$ has prototype
57 $codei%
58  const %Vector% &%d%
59 %$$.
60 It is tested to see if $icode%d%[0]%$$ it is equal to $latex \det ( X )$$.
61 
62 $head Vector$$
63 If $icode y$$ is a $icode Vector$$ object,
64 it must support the syntax
65 $codei%
66  %y%[%i%]
67 %$$
68 where $icode i$$ has type $code size_t$$ with value less than 9.
69 This must return a $code double$$ value corresponding to the $th i$$
70 element of the vector $icode y$$.
71 This is the only requirement of the type $icode Vector$$.
72 (Note that only the first element of the vector $icode d$$ is used.)
73 
74 $head ok$$
75 The return value $icode ok$$ has prototype
76 $codei%
77  bool %ok%
78 %$$
79 It is true, if the determinant $icode%d%[0]%$$
80 passes the test and false otherwise.
81 
82 $children%
83  omh/det_33_hpp.omh
84 %$$
85 
86 $head Source Code$$
87 The file
88 $cref det_33.hpp$$
89 contains the source code for this template function.
90 
91 $end
92 ------------------------------------------------------------------------------
93 */
94 // BEGIN C++
96 namespace CppAD {
97 template <class Vector>
98  bool det_33(const Vector &x, const Vector &d)
99  { bool ok = true;
100  double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
101 
102  // use expansion by minors to compute the determinant by hand
103  double check = 0.;
104  check += x[0] * ( x[4] * x[8] - x[5] * x[7] );
105  check -= x[1] * ( x[3] * x[8] - x[5] * x[6] );
106  check += x[2] * ( x[3] * x[7] - x[4] * x[6] );
107 
108  ok &= CppAD::NearEqual(check, d[0], eps99, eps99);
109 
110  return ok;
111  }
112 }
113 // END C++
114 # endif
bool det_33(const Vector &x, const Vector &d)
Definition: det_33.hpp:98
Type epsilon(void)
Definition: epsilon.hpp:56
bool NearEqual(const Type &x, const Type &y, const Type &r, const Type &a)
Definition: near_equal.hpp:168