Example #1
0
void StaticMatrixTest::invert()
{
    chemkit::StaticMatrix<chemkit::Float, 3, 3> matrix3;
    matrix3(0, 0) = 1;
    matrix3(0, 1) = 2;
    matrix3(0, 2) = 3;
    matrix3(1, 0) = 0;
    matrix3(1, 1) = 1;
    matrix3(1, 2) = 0;
    matrix3(2, 0) = 4;
    matrix3(2, 1) = 0;
    matrix3(2, 2) = 4;

    chemkit::StaticMatrix<chemkit::Float, 3, 3> inverse3 = matrix3.inverted();
    QCOMPARE(inverse3(0, 0), chemkit::Float(-0.5));
    QCOMPARE(inverse3(0, 1), chemkit::Float(1.0));
    QCOMPARE(inverse3(0, 2), chemkit::Float(0.375));
    QCOMPARE(inverse3(1, 0), chemkit::Float(0.0));
    QCOMPARE(inverse3(1, 1), chemkit::Float(1.0));
    QCOMPARE(inverse3(1, 2), chemkit::Float(0.0));
    QCOMPARE(inverse3(2, 0), chemkit::Float(0.5));
    QCOMPARE(inverse3(2, 1), chemkit::Float(-1.0));
    QCOMPARE(inverse3(2, 2), chemkit::Float(-0.125));
}
int main(int argc, char **argv)
{
	double a = 1234.0;
	double b;
	double r2,r3,r4,r5;

	b = 1.0 / a;
	r2 = inverse2(a);
	r3 = inverse3(a);
	r4 = inverse4(a);
	r5 = inverse5(a);

	printf("	   a = %5.16lf\n", a);
	printf("true 1/a = %5.16lf\n", b);
	printf("	  r2 = %5.16lf\n", r2);
	printf("	  r3 = %5.16lf\n", r3);
	printf("	  r4 = %5.16lf\n", r4);
	printf("	  r5 = %5.16lf\n", r5);

	return 0;
}