Game Development Reference
In-Depth Information
Listing 16.5. The LURefineSolution() function uses Equation (16.25) to improve the solution
x to the linear system
Mx .
=
Parameters
n
The size of the matrix M .
m
A pointer to the entries of the matrix M . The entries must be stored in column-
major order.
d
A pointer to the entries of the matrix D . This should be the same pointer that was
passed to the m parameter of the LUDecompose() function.
index
A pointer to the array of row permutation indexes returned by the LUDecom-
pose() function.
A pointer to an array of n constant values representing the vector r for which the
linear system
r
Mxr was originally solved.
=
x
A pointer to the array containing the n solutions representing the vector x . This
function refines these solutions.
void LURefineSolution( int n, const float *m, const float *d,
const unsigned short *index, const float *r, float *x)
{
float *t = new float [n];
for ( int i = 0; i < n; i++)
{
double q = -r[i];
for ( int k = 0; k < n; k++) q += m[k * n + i] * x[k];
t[i] = ( float ) q;
}
LUBacksubstitute(n, d, index, t, t);
for ( int i = 0; i < n; i++) x[i] -= t[i];
delete [] t;
}
Search Nedrilad ::




Custom Search