Files Classes Functions Hierarchy
#include <gausselim.h>
Public Member Functions | |
| gausselim (T *mat_, uintc dim_) | |
| Supply matrix A and C for equation AX = C. | |
| ~gausselim () | |
| Memory cleanup. | |
| boolc | eval () |
| Solve the system for a diagonal of ones. | |
| void | columnC (T *C) const |
| Gets column C. | |
| void | rowget (uintc i) |
| Writes the row to x. | |
| void | rowput (uintc i) |
| Writes x to the i'th row. | |
| void | mult (T const alpha) |
| alpha*x -> x. | |
| void | swap (uintc i, uintc k) |
| Swap the rows. | |
| void | norm (uintc row, uintc col) |
| Normalize by dividing the row by mat[row][col]. | |
| boolc | pivot (uintc k) |
| Pivotes the row with the highest magitude in the k'th column of rows k,k+1,. | |
| void | substitute (uintc i) |
| Normalize i and substitue into all other equations. | |
| operator stringc () const | |
| Serialize this object by writing it out as a string. | |
Public Attributes | |
| T * | mat |
| Matrix {A,C} where AX=C. | |
| T * | row |
| Tempory row variable. | |
| uintc | dim |
| dim=N. | |
Features: partial pivoting. Reference: An Introduction to Numerical Analysis by K. Atkinson, 2nd edition, pages 515+ .
//x + 5y = 11
//x + y + z = 0
//2x + z = -1
double e3[] =
{
1.0, 5.0, 0.0, 11.0,
1.0, 1.0, 1.0, 0.0,
2.0, 0.0, 1.0, -1.0
};
gausselim<double> g(e3,3);
g.eval();
g.print();
Definition at line 34 of file gausselim.h.
Supply matrix A and C for equation AX = C.
Definition at line 47 of file gausselim.h.
References gausselim< T >::dim, and gausselim< T >::row.
Memory cleanup.
Definition at line 51 of file gausselim.h.
References gausselim< T >::row.
00052 { delete[] row; }
Gets column C.
After solving the equation, lets you extract the solution.
Definition at line 94 of file gausselim.h.
References gausselim< T >::dim, and gausselim< T >::mat.
Referenced by tetrahedron< PT, PD >::circumcenter(), and gausselimtest::test02().
Solve the system for a diagonal of ones.
The last column C is the solution to the system.
Definition at line 101 of file gausselim.h.
References gausselim< T >::dim, gausselim< T >::pivot(), and gausselim< T >::substitute().
Referenced by tetrahedron< PT, PD >::circumcenter(), gausselimtest::test01(), and gausselimtest::test02().
00102 { 00103 for (uint i=0; i<dim; ++i) 00104 { 00105 if (pivot(i)==false) 00106 return false; 00107 00108 substitute(i); 00109 } 00110 00111 return true; 00112 }
alpha*x -> x.
Definition at line 194 of file gausselim.h.
References gausselim< T >::dim, and gausselim< T >::row.
Normalize by dividing the row by mat[row][col].
Definition at line 201 of file gausselim.h.
References gausselim< T >::dim, and gausselim< T >::mat.
Referenced by gausselim< T >::substitute().
00202 { 00203 assert(row<dim); 00204 assert(col<dim); 00205 00206 uint b = row*(dim+1); 00207 00208 T alpha = mat[b+col]; 00209 if (alpha==0) 00210 return; 00211 00212 alpha = 1.0/alpha; 00213 00214 for (uint i=0; i<dim+1; ++i) 00215 mat[b++] *= alpha; 00216 }
Serialize this object by writing it out as a string.
Definition at line 238 of file gausselim.h.
References gausselim< T >::dim, and gausselim< T >::mat.
00239 { 00240 stringstream ss; 00241 00242 for (uint i=0; i<dim; ++i) 00243 { 00244 for (uint k=0; k<dim+1; ++k) 00245 { 00246 ss << mat[i*(dim+1)+k] << " "; 00247 } 00248 if (i!=dim-1) 00249 ss << "\n"; 00250 } 00251 00252 return ss.str(); 00253 }
Pivotes the row with the highest magitude in the k'th column of rows k,k+1,.
.,N-1.
Definition at line 143 of file gausselim.h.
References gausselim< T >::dim, gausselim< T >::mat, and gausselim< T >::swap().
Referenced by gausselim< T >::eval().
00144 { 00145 assert(k<dim); 00146 00147 T lgnum = mat[ k*(dim+1) + k ]; 00148 T lgnum2 = lgnum*lgnum; 00149 uint lgi = k; 00150 T x; 00151 T x2; 00152 for (uint i=k+1; i<dim; ++i) 00153 { 00154 x = mat[ i*(dim+1) + k ]; 00155 x2 = x*x; 00156 if (x2>lgnum2) 00157 { 00158 lgnum2 = x2; 00159 lgnum = x; 00160 lgi = i; 00161 } 00162 } 00163 00164 if (k!=lgi) 00165 swap(k,lgi); 00166 00167 if (lgnum2 < zero<T>::val ) 00168 return false; 00169 00170 return true; 00171 }
Writes the row to x.
Definition at line 174 of file gausselim.h.
References gausselim< T >::dim, gausselim< T >::mat, and gausselim< T >::row.
Referenced by gausselim< T >::substitute().
00175 { 00176 assert(i<dim); 00177 00178 uint b = i*(dim+1); 00179 for (uint k=0; k<dim+1; ++k) 00180 row[k] = mat[b+k]; 00181 }
Writes x to the i'th row.
Definition at line 184 of file gausselim.h.
References gausselim< T >::dim, gausselim< T >::mat, and gausselim< T >::row.
00185 { 00186 assert(i<dim); 00187 00188 uint b = i*(dim+1); 00189 for (uint k=0; k<dim+1; ++k) 00190 mat[b+k] = row[k]; 00191 }
Normalize i and substitue into all other equations.
Definition at line 115 of file gausselim.h.
References gausselim< T >::dim, gausselim< T >::mat, gausselim< T >::norm(), r, gausselim< T >::row, and gausselim< T >::rowget().
Referenced by gausselim< T >::eval().
00116 { 00117 norm(k,k); 00118 00119 rowget(k); 00120 for (uint i=0; i<dim+1; ++i) 00121 row[i] *= -1; 00122 00123 uint b=0; 00124 T r; 00125 00126 for (uint i=0; i<dim; ++i) 00127 { 00128 if (i==k) 00129 { 00130 b += (dim+1); 00131 continue; 00132 } 00133 00134 r = mat[b+k]; 00135 00136 for (uint m=0; m<dim+1; ++m) 00137 mat[b++] += row[m]*r; 00138 } 00139 00140 }
Swap the rows.
Definition at line 219 of file gausselim.h.
References gausselim< T >::dim, and gausselim< T >::mat.
Referenced by gausselim< T >::pivot().
00220 { 00221 assert(i<dim); 00222 assert(k<dim); 00223 00224 T t; 00225 uint bi = i*(dim+1); 00226 uint bk = k*(dim+1); 00227 for (uint j=0; j<dim+1; ++j) 00228 { 00229 t = mat[bi]; 00230 mat[bi] = mat[bk]; 00231 mat[bk] = t; 00232 ++bi; 00233 ++bk; 00234 } 00235 }
dim=N.
Definition at line 44 of file gausselim.h.
Referenced by gausselim< T >::columnC(), gausselim< T >::eval(), gausselim< T >::gausselim(), gausselim< T >::mult(), gausselim< T >::norm(), gausselim< T >::operator stringc(), gausselim< T >::pivot(), gausselim< T >::rowget(), gausselim< T >::rowput(), gausselim< T >::substitute(), and gausselim< T >::swap().
Matrix {A,C} where AX=C.
Definition at line 40 of file gausselim.h.
Referenced by gausselim< T >::columnC(), gausselim< T >::norm(), gausselim< T >::operator stringc(), gausselim< T >::pivot(), gausselim< T >::rowget(), gausselim< T >::rowput(), gausselim< T >::substitute(), and gausselim< T >::swap().
Tempory row variable.
Definition at line 42 of file gausselim.h.
Referenced by gausselim< T >::gausselim(), gausselim< T >::mult(), gausselim< T >::rowget(), gausselim< T >::rowput(), gausselim< T >::substitute(), and gausselim< T >::~gausselim().
1.5.8