52 #ifndef MSQ_USE_OLD_IO_HEADERS
57 #include <strstream.h>
60 #ifndef MSQ_USE_OLD_C_HEADERS
85 { memcpy(
v_, v, 9*
sizeof(
double)); }
87 void set(
const double& val)
89 v_[0]=val;
v_[1]=val;
v_[2]=val;
90 v_[3]=val;
v_[4]=val;
v_[5]=val;
91 v_[6]=val;
v_[7]=val;
v_[8]=val;
96 #ifdef MSQ_USE_OLD_IO_HEADERS
99 std::istringstream ins(s);
101 ins>>
v_[0]; ins>>v_[1]; ins>>v_[2];
102 ins>>v_[3]; ins>>v_[4]; ins>>v_[5];
103 ins>>v_[6]; ins>>v_[7]; ins>>v_[8];
169 v_[0]=0.;
v_[1]=0.;
v_[2]=0.;
170 v_[3]=0.;
v_[4]=0.;
v_[5]=0.;
171 v_[6]=0.;
v_[7]=0.;
v_[8]=0.;
252 for (
size_t i=0;
i<3; ++
i)
254 for (
size_t j=0;
j<3; ++
j)
263 for (
size_t i=0;
i<3;
i++)
264 for (
size_t j=0;
j<3;
j++)
276 return (memcmp(lhs.
v_, rhs.
v_, 9*
sizeof(
double)) == 0);
280 return (memcmp(lhs.
v_, rhs.
v_, 9*
sizeof(
double)) != 0);
289 for (i=0; i<3; ++
i) {
290 tmp[
i][0] = A[
i][0] + B[
i][0];
291 tmp[
i][1] = A[
i][1] + B[
i][1];
292 tmp[
i][2] = A[
i][2] + B[
i][2];
303 for (i=0; i<3; ++
i) {
304 tmp[
i][0] = A[
i][0] - B[
i][0];
305 tmp[
i][1] = A[
i][1] - B[
i][1];
306 tmp[
i][2] = A[
i][2] - B[
i][2];
317 for (i=0; i<3; ++
i) {
318 tmp[
i][0] = A[
i][0] * B[
i][0];
319 tmp[
i][1] = A[
i][1] * B[
i][1];
320 tmp[
i][2] = A[
i][2] * B[
i][2];
329 for (
int i=0;
i<3; ++
i) {
330 fro += A[0][
i]*A[0][
i] + A[1][
i]*A[1][
i] + A[2][
i]*A[2][
i] ;
339 for (i=0; i<3; ++
i) {
340 S[size_t(0)][
i] = A[
i][0];
341 S[size_t(1)][
i] = A[
i][1];
342 S[size_t(2)][
i] = A[
i][2];
349 v_[0] += rhs.
v_[0];
v_[1] += rhs.
v_[1];
v_[2] += rhs.
v_[2];
350 v_[3] += rhs.
v_[3];
v_[4] += rhs.
v_[4];
v_[5] += rhs.
v_[5];
351 v_[6] += rhs.
v_[6];
v_[7] += rhs.
v_[7];
v_[8] += rhs.
v_[8];
356 v_[0] -= rhs.
v_[0];
v_[1] -= rhs.
v_[1];
v_[2] -= rhs.
v_[2];
357 v_[3] -= rhs.
v_[3];
v_[4] -= rhs.
v_[4];
v_[5] -= rhs.
v_[5];
358 v_[6] -= rhs.
v_[6];
v_[7] -= rhs.
v_[7];
v_[8] -= rhs.
v_[8];
374 tmp.
v_[0] =
v_[0] + B.
v_[0];
375 tmp.
v_[1] =
v_[1] + B.
v_[3];
376 tmp.
v_[2] =
v_[2] + B.
v_[6];
378 tmp.
v_[3] =
v_[3] + B.
v_[1];
379 tmp.
v_[4] =
v_[4] + B.
v_[4];
380 tmp.
v_[5] =
v_[5] + B.
v_[7];
382 tmp.
v_[6] =
v_[6] + B.
v_[2];
383 tmp.
v_[7] =
v_[7] + B.
v_[5];
384 tmp.
v_[8] =
v_[8] + B.
v_[8];
441 for (
size_t i=0;
i<3; ++
i)
442 for (
size_t k=0;
k<3; ++
k)
445 for (
size_t j=0;
j<3;
j++)
446 sum = sum + A[
i][
j] * B[
j][
k];
456 temp[0][0]=
v_[0] *
s; temp[0][1]=
v_[1] *
s; temp[0][2]=
v_[2] *
s;
457 temp[1][0]=
v_[3] *
s; temp[1][1]=
v_[4] *
s; temp[1][2]=
v_[5] *
s;
458 temp[2][0]=
v_[6] *
s; temp[2][1]=
v_[7] *
s; temp[2][2]=
v_[8] *
s;
465 return (A.operator*(s));
476 for (
size_t i=0;
i<3; ++
i)
477 for (
size_t k=0;
k<3; ++
k)
482 for (
size_t j=0;
j<3; ++
j)
484 sum += *row_i * *col_k;
497 for (
size_t i=0;
i<3; ++
i)
499 const double* rowi = A[
i];
500 tmp[
i] = rowi[0]*x[0] + rowi[1]*x[1] + rowi[2]*x[2];
513 for (
size_t i=0;
i<3; ++
i)
515 const double* rowi = A[
i];
516 for (
size_t j=0;
j<3; ++
j)
517 res[
j] += rowi[
j] * x[
i];
544 B.
v_[0] += a*A.
v_[0]; B.
v_[1] += a*A.
v_[1]; B.
v_[2] += a*A.
v_[2];
545 B.
v_[3] += a*A.
v_[3]; B.
v_[4] += a*A.
v_[4]; B.
v_[5] += a*A.
v_[5];
546 B.
v_[6] += a*A.
v_[6]; B.
v_[7] += a*A.
v_[7]; B.
v_[8] += a*A.
v_[8];
550 return ( A.
v_[0]*(A.
v_[4]*A.
v_[8]-A.
v_[7]*A.
v_[5])
556 double inv_detA = 1 / (
det(A));
558 Ainv[0][0] = inv_detA*( A.
v_[4]*A.
v_[8]-A.
v_[5]*A.
v_[7] );
559 Ainv[0][1] = inv_detA*( A.
v_[2]*A.
v_[7]-A.
v_[8]*A.
v_[1] );
560 Ainv[0][2] = inv_detA*( A.
v_[1]*A.
v_[5]-A.
v_[4]*A.
v_[2] );
562 Ainv[1][0] = inv_detA*( A.
v_[5]*A.
v_[6]-A.
v_[8]*A.
v_[3] );
563 Ainv[1][1] = inv_detA*( A.
v_[0]*A.
v_[8]-A.
v_[6]*A.
v_[2] );
564 Ainv[1][2] = inv_detA*( A.
v_[2]*A.
v_[3]-A.
v_[5]*A.
v_[0] );
566 Ainv[2][0] = inv_detA*( A.
v_[3]*A.
v_[7]-A.
v_[6]*A.
v_[4] );
567 Ainv[2][1] = inv_detA*( A.
v_[1]*A.
v_[6]-A.
v_[7]*A.
v_[0] );
568 Ainv[2][2] = inv_detA*( A.
v_[0]*A.
v_[4]-A.
v_[3]*A.
v_[1] );
576 double inv_detA = 1 / (
det(A) );
578 Ainv[0][0] = inv_detA*( A.
v_[4]*A.
v_[8]-A.
v_[5]*A.
v_[7] );
579 Ainv[0][1] = inv_detA*( A.
v_[2]*A.
v_[7]-A.
v_[8]*A.
v_[1] );
580 Ainv[0][2] = inv_detA*( A.
v_[1]*A.
v_[5]-A.
v_[4]*A.
v_[2] );
582 Ainv[1][0] = inv_detA*( A.
v_[5]*A.
v_[6]-A.
v_[8]*A.
v_[3] );
583 Ainv[1][1] = inv_detA*( A.
v_[0]*A.
v_[8]-A.
v_[6]*A.
v_[2] );
584 Ainv[1][2] = inv_detA*( A.
v_[2]*A.
v_[3]-A.
v_[5]*A.
v_[0] );
586 Ainv[2][0] = inv_detA*( A.
v_[3]*A.
v_[7]-A.
v_[6]*A.
v_[4] );
587 Ainv[2][1] = inv_detA*( A.
v_[1]*A.
v_[6]-A.
v_[7]*A.
v_[0] );
588 Ainv[2][2] = inv_detA*( A.
v_[0]*A.
v_[4]-A.
v_[3]*A.
v_[1] );
601 R[0][0] =
sqrt(Q[0][0]*Q[0][0] + Q[1][0]*Q[1][0] + Q[2][0]*Q[2][0]);
608 R[0][1] = Q[0][0]*Q[0][1] + Q[1][0]*Q[1][1] + Q[2][0]*Q[2][1];
609 Q[0][1] -= Q[0][0]*R[0][1];
610 Q[1][1] -= Q[1][0]*R[0][1];
611 Q[2][1] -= Q[2][0]*R[0][1];
613 R[0][2] = Q[0][0]*Q[0][2] + Q[1][0]*Q[1][2] + Q[2][0]*Q[2][2];
614 Q[0][2] -= Q[0][0]*R[0][2];
615 Q[1][2] -= Q[1][0]*R[0][2];
616 Q[2][2] -= Q[2][0]*R[0][2];
618 R[1][1] =
sqrt(Q[0][1]*Q[0][1] + Q[1][1]*Q[1][1] + Q[2][1]*Q[2][1]);
624 R[1][2] = Q[0][1]*Q[0][2] + Q[1][1]*Q[1][2] + Q[2][1]*Q[2][2];
625 Q[0][2] -= Q[0][1]*R[1][2];
626 Q[1][2] -= Q[1][1]*R[1][2];
627 Q[2][2] -= Q[2][1]*R[1][2];
629 R[2][2] =
sqrt(Q[0][2]*Q[0][2] + Q[1][2]*Q[1][2] + Q[2][2]*Q[2][2]);
638 #endif // Matrix3D_hpp
Matrix3D()
Default constructor sets all entries to 0.
Matrix3D & operator=(const char *s)
for test purposes, matrices can be assigned as follows
Matrix3D(const Matrix3D &A)
Matrix3D & operator=(const double &scalar)
void plusEqaA(Matrix3D &B, const double a, const Matrix3D &A)
friend void inv(Matrix3D &B, const Matrix3D &A)
void zero()
Sets all entries to zero (more efficient than assignement).
const Matrix3D operator*(const Matrix3D &A, const Matrix3D &B)
Matrix3D(const char *s)
for test purposes, matrices can be instantiated as
friend const Matrix3D operator*(const Matrix3D &A, const Matrix3D &B)
msq_stdio::istream & operator>>(msq_stdio::istream &s, Matrix3D &A)
bool operator!=(const Matrix3D &lhs, const Matrix3D &rhs)
void operator-=(const Matrix3D &rhs)
void plusEqAx(Vector3D &v, const Matrix3D &A, const Vector3D &x)
const double * operator[](unsigned i) const
returns a pointer to a row.
friend const Matrix3D operator-(const Matrix3D &A, const Matrix3D &B)
Matrix3D transpose(const Matrix3D &A)
friend void timesInvA(Matrix3D &B, const Matrix3D &A)
friend int matmult(Matrix3D &C, const Matrix3D &A, const Matrix3D &B)
Matrix3D & outer_product(const Vector3D &v1, const Vector3D &v2)
Computes .
void plusEqTransAx(Vector3D &v, const Matrix3D &A, const Vector3D &x)
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
friend double det(const Matrix3D &A)
determinant of matrix A, det(A).
friend double Frobenius_2(const Matrix3D &A)
Return the square of the Frobenius norm of A, i.e. sum (diag (A' * A))
void copy(const double *v)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
friend void plusEqaA(Matrix3D &B, const double a, const Matrix3D &A)
double Frobenius_2(const Matrix3D &A)
Return the square of the Frobenius norm of A, i.e. sum (diag (A' * A))
int matmult(Matrix3D &C, const Matrix3D &A, const Matrix3D &B)
void plus_transpose_equal(const Matrix3D &B)
friend bool operator!=(const Matrix3D &lhs, const Matrix3D &rhs)
void QR(Matrix3D &Q, Matrix3D &R, const Matrix3D &A)
Matrix3D(const double &value)
sets all entries of the matrix to value.
3*3 Matric class, row-oriented, 0-based [i][j] indexing.
bool operator==(const Matrix3D &lhs, const Matrix3D &rhs)
double column_length(int i) const
returns the column length – i is 0-based.
const Matrix3D operator-(const Matrix3D &A, const Matrix3D &B)
void timesInvA(Matrix3D &B, const Matrix3D &A)
friend void eqAx(Vector3D &v, const Matrix3D &A, const Vector3D &x)
friend Matrix3D transpose(const Matrix3D &A)
Matrix3D plus_transpose(const Matrix3D &B) const
const Matrix3D mult_element(const Matrix3D &A, const Matrix3D &B)
Multiplies entry by entry. This is NOT a matrix multiplication.
friend const Matrix3D mult_element(const Matrix3D &A, const Matrix3D &B)
Multiplies entry by entry. This is NOT a matrix multiplication.
void set(const double &val)
friend void plusEqTransAx(Vector3D &v, const Matrix3D &A, const Vector3D &x)
void operator+=(const Matrix3D &rhs)
const Matrix3D operator+(const Matrix3D &A, const Matrix3D &B)
double det(const Matrix3D &A)
friend const Matrix3D operator+(const Matrix3D &A, const Matrix3D &B)
void fill_lower_triangle()
void set_column(int j, const Vector3D &c)
Sets column j (0, 1 or 2) to Vector3D c.
Matrix3D & operator=(const Matrix3D &A)
void inv(Matrix3D &Ainv, const Matrix3D &A)
friend void QR(Matrix3D &Q, Matrix3D &R, const Matrix3D &A)
msq_stdio::ostream & operator<<(msq_stdio::ostream &s, const Matrix3D &A)
double * operator[](unsigned i)
returns a pointer to a row.
Matrix3D(const double *v)
sets matrix entries to values in array.
friend bool operator==(const Matrix3D &lhs, const Matrix3D &rhs)
friend void plusEqAx(Vector3D &v, const Matrix3D &A, const Vector3D &x)
void operator*=(const double &s)
multiplies each entry by the scalar s
void set_values(const char *s)
void eqAx(Vector3D &v, const Matrix3D &A, const Vector3D &x)