[ 簡単な説明 ] 行列ライブラリの使用例です。 |
/* test15.c */ #include <stdio.h> #include "sslib.h" void mprint(char *s, double a[], int m, int n); void mprint(char *s, double a[], int m, int n) { int i, j, k; printf("matrix : %s\n", s); for(i = k = 0; i < m; i++) { for(j = 0; j < n; j++, k++) printf("%13.6e ", a[k]); putchar('\n'); } } int main(void) { static double a[15] = { 3,-6, 7, 4,9999, 9, 0,-5,-2,9999, 5,-8, 6, 1,9999}; static double b[20] = {-6, 2,9999,9999,9999, 3,-9,9999,9999,9999, 5,-1,9999,9999,9999, 4, 1,9999,9999,9999}; static double av[4] = { 4.0, 1.0, 1.0, 2.0 }; double c[12], v[4], eps, *p; int i, j, k, l, la, lb, lc, m, n, nr, t; l = 3; m = 3; mprint("a", a, m, l); mprint("b", b, m, l); madd(a, b, c, l, l, l, m, l); mprint("a + b", c, m, l); msub(a, b, c, l, l, l, m, l); mprint("a + b", c, m, l); la = 5; lb = 5; lc = 4; m = 3; n = 4; k = 2; for(i = 0, p = c; i < m; i++) for (j = 0; j < lc; j++) *p++ = 0.; mprint("a", a, m, la); mprint("b", b, n, lb); mprint("c", c, m, lc); mmul2(a, b, c, la, lb, lc, m, n, k); mprint("a * b", c, m, lc); la = 5; m = 3; n = 3; mprint("before transposition a", a, m, la); mtra1(a, la, m, n); mprint("after transposition a", a, m, la); la = 5; lb = 5; m = 3; n = 4; mprint("before transposition a", a, m, la); mprint("before transposition b", b, n, lb); mtra2(a, b, la, lb, m, n); mprint("after transposition b", b, n, la); lc = 4; m = 3; for(i = t = 0; i < m; i++) for (j = 0; j < lc; j++, t++) c[t] = a[t]; mprint("matrix a", a, m, 5); mprint("matrix c", c, m, lc); printf("determinant = %22.15e\n", minver(c, lc, m, 1.e-6)); mprint("inversion c", c, m, lc); la = 5; lb = 5; mmul2(a, c, b, la, lc, lb, m, m, m); mprint("a * c", b, m, lb); eps = 1.0e-6; nr = 20; l = 2; mprint("matrix av", av, l, l); jacobi(av, v, l, l, &nr, eps); printf("the number of rotation = %d\n", nr); mprint("eigen values", av, l, l); mprint("eigen vectors", v, l, l); return 1; } |
matrix : a 3.000000e+00 -6.000000e+00 7.000000e+00 4.000000e+00 9.999000e+03 9.000000e+00 0.000000e+00 -5.000000e+00 -2.000000e+00 matrix : b -6.000000e+00 2.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 3.000000e+00 -9.000000e+00 9.999000e+03 9.999000e+03 matrix : a + b -3.000000e+00 -4.000000e+00 1.000600e+04 1.000300e+04 1.999800e+04 1.200000e+01 -9.000000e+00 9.994000e+03 9.997000e+03 matrix : a + b 9.000000e+00 -8.000000e+00 -9.992000e+03 -9.995000e+03 0.000000e+00 6.000000e+00 9.000000e+00 -1.000400e+04 -1.000100e+04 matrix : a 3.000000e+00 -6.000000e+00 7.000000e+00 4.000000e+00 9.999000e+03 9.000000e+00 0.000000e+00 -5.000000e+00 -2.000000e+00 9.999000e+03 5.000000e+00 -8.000000e+00 6.000000e+00 1.000000e+00 9.999000e+03 matrix : b -6.000000e+00 2.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 3.000000e+00 -9.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 5.000000e+00 -1.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 4.000000e+00 1.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 matrix : c 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 matrix : a * b 1.500000e+01 5.700000e+01 0.000000e+00 0.000000e+00 -8.700000e+01 2.100000e+01 0.000000e+00 0.000000e+00 -2.000000e+01 7.700000e+01 0.000000e+00 0.000000e+00 matrix : before transposition a 3.000000e+00 -6.000000e+00 7.000000e+00 4.000000e+00 9.999000e+03 9.000000e+00 0.000000e+00 -5.000000e+00 -2.000000e+00 9.999000e+03 5.000000e+00 -8.000000e+00 6.000000e+00 1.000000e+00 9.999000e+03 matrix : after transposition a 3.000000e+00 9.000000e+00 5.000000e+00 4.000000e+00 9.999000e+03 -6.000000e+00 0.000000e+00 -8.000000e+00 -2.000000e+00 9.999000e+03 7.000000e+00 -5.000000e+00 6.000000e+00 1.000000e+00 9.999000e+03 matrix : before transposition a 3.000000e+00 9.000000e+00 5.000000e+00 4.000000e+00 9.999000e+03 -6.000000e+00 0.000000e+00 -8.000000e+00 -2.000000e+00 9.999000e+03 7.000000e+00 -5.000000e+00 6.000000e+00 1.000000e+00 9.999000e+03 matrix : before transposition b -6.000000e+00 2.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 3.000000e+00 -9.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 5.000000e+00 -1.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 4.000000e+00 1.000000e+00 9.999000e+03 9.999000e+03 9.999000e+03 matrix : after transposition b 3.000000e+00 -6.000000e+00 7.000000e+00 9.999000e+03 9.999000e+03 9.000000e+00 0.000000e+00 -5.000000e+00 9.999000e+03 9.999000e+03 5.000000e+00 -8.000000e+00 6.000000e+00 9.999000e+03 9.999000e+03 4.000000e+00 -2.000000e+00 1.000000e+00 9.999000e+03 9.999000e+03 matrix : matrix a 3.000000e+00 9.000000e+00 5.000000e+00 4.000000e+00 9.999000e+03 -6.000000e+00 0.000000e+00 -8.000000e+00 -2.000000e+00 9.999000e+03 7.000000e+00 -5.000000e+00 6.000000e+00 1.000000e+00 9.999000e+03 matrix : matrix c 3.000000e+00 9.000000e+00 5.000000e+00 4.000000e+00 9.999000e+03 -6.000000e+00 0.000000e+00 -8.000000e+00 -2.000000e+00 9.999000e+03 7.000000e+00 -5.000000e+00 determinant = 4.992698820000000e+08 matrix : inversion c -8.412284e-08 1.000100e-04 6.008774e-08 4.000000e+00 -1.401907e-04 6.209067e-08 1.001362e-04 -8.000000e+00 2.002524e-01 -6.011779e-05 -1.802813e-04 -5.000000e+00 matrix : a * c 1.000000e+00 0.000000e+00 0.000000e+00 9.999000e+03 9.999000e+03 -1.602019e+00 -1.191179e-04 1.441889e-03 9.999000e+03 9.999000e+03 1.202215e+00 3.390531e-04 -1.581948e-03 9.999000e+03 9.999000e+03 matrix : matrix av 4.000000e+00 1.000000e+00 1.000000e+00 2.000000e+00 the number of rotation = 1 matrix : eigen values 4.414214e+00 0.000000e+00 0.000000e+00 1.585786e+00 matrix : eigen vectors 9.238795e-01 -3.826834e-01 3.826834e-01 9.238795e-01 |