Prev Next Index-> contents reference index search external Up-> CppAD speed speed_utility mat_sum_sq mat_sum_sq.cpp speed-> speed_main speed_utility speed_double speed_adolc speed_cppad speed_fadbad speed_sacado speed_utility-> det_by_lu det_of_minor det_by_minor det_33 det_grad_33 mat_sum_sq ode_evaluate sparse_jac_fun sparse_hes_fun uniform_01 mat_sum_sq-> mat_sum_sq.cpp mat_sum_sq.hpp mat_sum_sq.cpp Headings

$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$
Sum of the Elements of the Square of a Matrix: Example and Test
# include <vector> # include <cstddef> # include <cppad/utility/vector.hpp> # include <cppad/speed/mat_sum_sq.hpp> bool mat_sum_sq() { bool ok = true; double x_00, x_01, x_10, x_11, check; // dimension of the matrices x, y, and the result z size_t n = 2; CppAD::vector<double> x(n * n), y(n * n), z(1); // x = [ 1 2 ; 3 4 ] x[0] = x_00 = 1.; x[1] = x_01 = 2.; x[2] = x_10 = 3.; x[3] = x_11 = 4.; // compute y = x * x and z = sum of elements in y CppAD::mat_sum_sq(n, x, y, z); // check y_00 check = x_00 * x_00 + x_01 * x_10; ok &= (check == y[0]); // check y_01 check = x_00 * x_01 + x_01 * x_11; ok &= (check == y[1]); // check y_10 check = x_10 * x_00 + x_11 * x_10; ok &= (check == y[2]); // check y_11 check = x_10 * x_01 + x_11 * x_11; ok &= (check == y[3]); // check z check = y[0] + y[1] + y[2] + y[3]; ok &= (check == z[0]); return ok; } 
Input File: speed/example/mat_sum_sq.cpp