12 for (
int i = 0; i <
mxNRows; i++ )
30 for (
int i = 0; i <
mxNRows; i++ )
58 for (
int i = 0; i <
NRows; i++)
78 for(
int i=0; i<nc; i++ )
98 fprintf(stderr,
"\nDimension compatibility error in %s()\n", __func__);
99 fprintf(stderr,
"A->NRows=%d; A->NCols=%d\n"
100 "B->NRows=%d; B->NCols=%d\n"
101 "C->NRows=%d; C->NCols=%d\n\n",
106 for (
int i = 0; i < A->
NRows; i++)
108 for (
int j = 0; j < B->
NCols; j++)
110 C->
Ent[i][j] = A->
Ent[i][0] * B->
Ent[0][j];
111 for (
int k = 1; k < A->
NCols; k++)
113 C->
Ent[i][j] += A->
Ent[i][k] * B->
Ent[k][j];
123 fprintf(stderr,
"\nDimension compatibility error in %s()\n", __func__);
124 fprintf(stderr,
"A->NRows=%d; A->NCols=%d\n"
125 "B->NRows=%d; B->NCols=%d\n",
130 for (
int i = 0; i < A->
NRows; i++)
132 for (
int j = 0; j < B->
NCols; j++)
135 for (
int k = 1; k < A->
NCols; k++)
137 C[A->
NRows * i + j] += A->
Ent[i][k] * B->
Ent[k][j];
148 fprintf(stderr,
"\nDimension compatibility error in %s()\n", __func__);
149 fprintf(stderr,
"A->NRows=%d; A->NCols=%d\n"
150 "B->NRows=%d; B->NCols=%d\n"
151 "C->NRows=%d; C->NCols=%d\n\n",
156 for (
int i = 0; i < A->
NCols; i++)
158 for (
int j = 0; j < B->
NCols; j++)
160 C->
Ent[i][j] = A->
Ent[0][i] * B->
Ent[0][j];
161 for (
int k = 1; k < A->
NRows; k++)
163 C->
Ent[i][j] += A->
Ent[k][i] * B->
Ent[k][j];
174 fprintf(stderr,
"\nDimension compatibility error in %s()\n", __func__);
175 fprintf(stderr,
"A->NRows=%d; A->NCols=%d\n"
176 "B->NCols=%d; B->NRows=%d\n"
177 "C->NRows=%d; C->NCols=%d\n\n",
182 for (
int i = 0; i < A->
NRows; i++)
184 for (
int j = 0; j < B->
NRows; j++)
186 C->
Ent[i][j] = A->
Ent[i][0] * B->
Ent[j][0];
187 for (
int k = 1; k < A->
NCols; k++)
189 C->
Ent[i][j] += A->
Ent[i][k] * B->
Ent[j][k];
200 fprintf(stderr,
"\nDimension compatibility error in %s()\n", __func__);
201 fprintf(stderr,
"A->NRows=%d; A->NCols=%d\n"
202 "B->NRows=%d; B->NCols=%d\n"
203 "C->NRows=%d; C->NCols=%d\n\n",
208 for (
int i = 0; i < A->
NRows; i++)
210 for (
int j = 0; j < B->
NCols; j++)
212 C->
Ent[i][j] = A->
Ent[i][j] + B->
Ent[i][j];
229 for (
int i = 0; i < A->
NRows; i++)
230 for (
int j = 0; j < A->
NCols; j++)
242 fprintf(stderr,
"\nError in %s(); M.NRows != M.NCols\n", __func__ );
249 det = M->
Ent[0][0] * M->
Ent[1][1] - M->
Ent[0][1] * M->
Ent[1][0];
252 for (
int i = 0; i < M->
NRows; i++)
256 det += temp * M->
Ent[0][i];
262 for (
int i = 0; i < M->
NRows; i++)
265 for ( j = 0, m = 0; j < M->
NRows; j++, m++)
269 for (
int k = 1; k < M->
NCols; k++, n++)
273 tempM.
Ent[m][n] = M->
Ent[j][k];
282 fprintf(stderr,
"\nError in Det routine; M.NRows must = 2,3, or 4...\n"
283 "The 4 case should be general enough for all matrices\n"
284 "of size>4 but should be checked; M.NRows=%d\n", M->
NRows);
299 fprintf(stderr,
"\nError in %s(); M.NRows != M.NCols\n", __func__ );
303 for (
int i = 0; i < M->
NRows; i++)
304 trace += M->
Ent[i][i];
324 fprintf( stderr,
"%s(): Unable to decompose nonsquare matrix\n", __func__ );
330 for (
int i = 0; i <
mxNRows; i++ )
339 for (
int i = 0; i <
NRows; i++ )
359 fprintf( stderr,
"%s(): Trying to solve undecomposed matrix\n", __func__ );
383 for (
int i = 0; i <
NRows; i++ )
385 for (
int j = 0; j <
NRows; j++ )
388 for (
int j = 0; j <
NRows; j++ )
389 A_inv->
Ent[j][i] = soln[j];
417 for (
int i = 0; i < A_.
NRows; i++ )
419 for (
int j = 0; j < A_.
NRows; j++ )
422 for (
int j = 0; j < A_.
NRows; j++ )
423 A_inv->
Ent[j][i] = soln[j];
449 for (
int i = 0; i <
NRows; i++ )
450 for (
int j = 0; j <
NCols; j++ )
451 A_t->
Ent[j][i] =
Ent[i][j];
457 for (
int i = 0; i <
NRows; i++ )
459 for (
int j = i + 1; j <
NRows; j++ )
480 double sin_th = sin(
angle);
481 double cos_th = cos(
angle);
483 static const int p[3][2] = { {1, 2},
487 const int *a = p[ax];
491 R->
Ent[a[0]][a[0]] = cos_th;
492 R->
Ent[a[0]][a[1]] = sin_th;
493 R->
Ent[a[1]][a[0]] = -sin_th;
494 R->
Ent[a[1]][a[1]] = cos_th;
512 for (
int i = 0; i < A->
NRows; i++ )
514 c[i] = A->
Ent[i][0] * b[0];
515 for (
int j = 1; j < A->
NCols; j++ )
516 c[i] += A->
Ent[i][j] * b[j];
524 const int BRows = B->
NRows;
525 const int BCols = B->
NCols;
530 Real c1 = C[0], c2 = C[1], c3 = C[2], c4 = C[3], c5 = C[4], c6 = C[5];
532 for (
int k = 0; k < BRows; k++)
533 result[k] += (c1 * B->
Ent[k][0] + c2 * B->
Ent[k][1] + c3 * B->
Ent[k][2] + c4 * B->
Ent[k][3] + c5 * B->
Ent[k][4] + c6 * B->
Ent[k][5]) * dx;
537 for (
int k = 0; k < BRows; k++)
538 for (
int j = 0; j < BCols; j++)
539 result[k] += B->
Ent[k][j] * C[j] * dx;
545 const int BRows = B->
NRows;
546 const int BCols = B->
NCols;
548 const int RRows = result->
NRows;
549 const int RCols = result->
NCols;
552 if ( RRows != RCols || RRows != BRows || !BRows || !BCols)
554 fprintf(stderr,
"\nDimension compatibility error in %s()\n", __func__);
555 fprintf(stderr,
"B->NRows=%d; B->NCols=%d\n"
556 "result->NRows=%d; result->NCols=%d\n\n",
557 BRows, BCols, RRows, RCols);
565 Real c11 = C[0], c12 = C[1], c13 = C[2], c14 = C[3], c15 = C[4], c16 = C[5];
566 Real c21 = C[6], c22 = C[7], c23 = C[8], c24 = C[9], c25 = C[10], c26 = C[11];
567 Real c31 = C[12], c32 = C[13], c33 = C[14], c34 = C[15], c35 = C[16], c36 = C[17];
568 Real c41 = C[18], c42 = C[19], c43 = C[20], c44 = C[21], c45 = C[22], c46 = C[23];
569 Real c51 = C[24], c52 = C[25], c53 = C[26], c54 = C[27], c55 = C[28], c56 = C[29];
570 Real c61 = C[30], c62 = C[31], c63 = C[32], c64 = C[33], c65 = C[34], c66 = C[35];
573 for (
int i = 0; i < BRows; i++)
577 Real b1 = B->
Ent[i][0], b2 = B->
Ent[i][1], b3 = B->
Ent[i][2], b4 = B->
Ent[i][3], b5 = B->
Ent[i][4], b6 = B->
Ent[i][5];
580 Real v1 = c11 * b1 + c21 * b2 + c31 * b3 + c41 * b4 + c51 * b5 + c61 * b6;
581 Real v2 = c12 * b1 + c22 * b2 + c32 * b3 + c42 * b4 + c52 * b5 + c62 * b6;
582 Real v3 = c13 * b1 + c23 * b2 + c33 * b3 + c43 * b4 + c53 * b5 + c63 * b6;
583 Real v4 = c14 * b1 + c24 * b2 + c34 * b3 + c44 * b4 + c54 * b5 + c64 * b6;
584 Real v5 = c15 * b1 + c25 * b2 + c35 * b3 + c45 * b4 + c55 * b5 + c65 * b6;
585 Real v6 = c16 * b1 + c26 * b2 + c36 * b3 + c46 * b4 + c56 * b5 + c66 * b6;
588 for (
int k = 0; k < BRows; k++)
589 result->
Ent[i][k] += (v1 * B->
Ent[k][0] + v2 * B->
Ent[k][1] + v3 * B->
Ent[k][2] + v4 * B->
Ent[k][3] + v5 * B->
Ent[k][4] + v6 * B->
Ent[k][5]) * dx;
599 for (
int i = 0; i < BRows; i++)
602 memset(tmp, 0., BCols *
sizeof(
Real));
605 for (
int j1 = 0; j1 < BCols; j1++)
606 for (
int j2 = 0; j2 < BCols; j2++)
607 tmp[j2] += B->
Ent[i][j1] * C[BCols * j1 + j2];
610 for (
int k = 0; k < BRows; k++)
613 for (
int j = 0; j < BCols; j++)
614 scalar_temp += tmp[j] * B->
Ent[k][j];
616 result->
Ent[i][k] += scalar_temp * dx;
626 for (
int i = 0; i < A->
NRows; i++)
628 for (
int j = 0; j < A->
NCols; j++)
629 printf(
"%12.8f\t", A->
Ent[i][j] );
void FM_Times_Scalar(FMatrix *A, Real a)
Real FMatrix_Det(FMatrix *M)
void B_C_BTrans(Real dx, FMatrix *B, Real *C, FMatrix *result)
void Print_FMatrix(FMatrix *A)
void FM_Plus_FM(FMatrix *A, FMatrix *B, FMatrix *C)
void FM_Times_FMinArray(FMatrix *A, FMatrix *B, Real *C)
Real FMatrix_Trace(FMatrix *M)
void FM_Times_Vec(Real dx, FMatrix *B, Real *C, Real *result)
FMatrix * FM_Rotate(FMatrix *R, double angle, int ax)
void TransFM_Times_FM(FMatrix *A, FMatrix *B, FMatrix *C)
Real * FM_X_Vec(FMatrix *A, Real *b, Real *c)
void FM_Times_FM(FMatrix *A, FMatrix *B, FMatrix *C)
void FM_Times_TransFM(FMatrix *A, FMatrix *B, FMatrix *C)
int mxNCols
max. number of cols
int NCols
actual number of cols
bool decomposed
true if decomposed
Real ** Ent
matrix entries
int * indx
indices for decomposition
int mxNRows
max. number of rows
FMatrix & operator=(FMatrix &)
Real ** base1
base1 version of matrix
FMatrix * Transpose(bool)
int NRows
actual number of rows
bool ludcmp(Real **a, size_t n, int *indx, Real *d)
void lubksb(Real **a, size_t n, int *indx, Real *b)
V angle(const vec3< V > &v1, const vec3< V > &v2)