CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions
LinearEquation3< T > Class Template Reference

#include <LinearEquation3.h>

Classes

class  Array3
 

Public Member Functions

Basic3DVector< Tsolution (const Basic3DVector< T > &row0, const Basic3DVector< T > &row1, const Basic3DVector< T > &row2, const Basic3DVector< T > &rhsvec) const
 

Detailed Description

template<class T>
class LinearEquation3< T >

Definition at line 13 of file LinearEquation3.h.

Member Function Documentation

template<class T>
Basic3DVector<T> LinearEquation3< T >::solution ( const Basic3DVector< T > &  row0,
const Basic3DVector< T > &  row1,
const Basic3DVector< T > &  row2,
const Basic3DVector< T > &  rhsvec 
) const
inline

Definition at line 55 of file LinearEquation3.h.

References abs, alignmentValidation::c1, LinearEquation3< T >::Array3< U >::subtractScaled(), and std::swap().

Referenced by ThreePlaneCrossing::crossing().

58  {
59 
60  // copy the input to internal "matrix"
61  Array3<T> row[3];
62  row[0] = row0;
63  row[1] = row1;
64  row[2] = row2;
65  Array3<T> rhs(rhsvec);
66 
67  // no implicit pivoting - rows expected to be normalized already
68 
69  // find pivot 0, i.e. row with largest first element
70  int i0 = std::abs(row[0][0]) > std::abs(row[1][0]) ? 0 : 1;
71  if (std::abs(row[i0][0]) < std::abs(row[2][0])) i0 = 2;
72 
73  int i1 = (i0+1)%3;
74  int i2 = (i0+2)%3;
75 
76  // zero the first column of rows i1 and i2
77  T c1 = row[i1][0] / row[i0][0];
78  // row[i1] -= c1*row[i0];
79  row[i1].subtractScaled( row[i0], c1);
80  rhs[i1] -= c1*rhs[i0];
81  T c2 = row[i2][0] / row[i0][0];
82  // row[i2] -= c2*row[i0];
83  row[i2].subtractScaled( row[i0], c2);
84  rhs[i2] -= c2*rhs[i0];
85 
86  // find pivot 1, i.e. which row (i1 or i2) has the largest second element
87  if (std::abs(row[i1][1]) < std::abs(row[i2][1])) std::swap( i1, i2);
88 
89  // zero the second column of row i2
90  T c3 = row[i2][1] / row[i1][1];
91  row[i2][1] -= c3 * row[i1][1];
92  row[i2][2] -= c3 * row[i1][2];
93  rhs[i2] -= c3*rhs[i1];
94 
95  // compute the solution
96  T x2 = rhs[i2] / row[i2][2];
97  T x1 = (rhs[i1] - x2*row[i1][2]) / row[i1][1];
98  T x0 = (rhs[i0] - x1*row[i0][1] - x2*row[i0][2]) / row[i0][0];
99 
100  return Basic3DVector<T>(x0, x1, x2);
101  }
#define abs(x)
Definition: mlp_lapack.h:159
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
long double T