00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <stdarg.h>
00025 #include <math.h>
00026 #include <assert.h>
00027 #include <it/io.h>
00028 #include <it/mat.h>
00029 #include <it/linalg.h>
00030
00031 int main ()
00032 {
00033 int i, j;
00034 const int K = 100;
00035 mat m1 = mat_new (2, 5);
00036 mat m2 = mat_new_alloc (5, 3, 6, 6);
00037 mat m3;
00038 mat m4 = mat_new (3, 3);
00039 mat m5, m6, m7, m8;
00040 m4[0][0] = 0.3;
00041 m4[0][1] = 0.2;
00042 m4[0][2] = 0.5;
00043 m4[1][0] = 0.1;
00044 m4[1][1] = 0.1;
00045 m4[1][2] = 0.8;
00046 m4[2][0] = 0.7;
00047 m4[2][1] = 0.2;
00048 m4[2][2] = 0.1;
00049
00050 printf
00051 ("height(m1) = %d\tmaxheight(m1) = %d\nwidth(m1) = %d\tmaxwidth(m1) = %d\n",
00052 mat_height (m1), mat_height_max (m1), mat_width (m1),
00053 mat_width_max (m1));
00054
00055 printf
00056 ("height(m1) = %d\tmaxheight(m1) = %d\nwidth(m1) = %d\tmaxwidth(m1) = %d\n",
00057 mat_height (m2), mat_height_max (m2), mat_width (m2),
00058 mat_width_max (m2));
00059
00060 mat_set (m1, 5);
00061 mat_set (m2, 4);
00062
00063 mat_mul_by (m1, 3);
00064 mat_decr (m1, 1);
00065
00066 for (i = 0; i < mat_height (m1); i++) {
00067 for (j = 0; j < mat_width (m1); j++)
00068 printf ("%.4f\t", m1[i][j]);
00069 printf ("\n");
00070 }
00071 printf ("\n");
00072
00073
00074 for (i = 0; i < mat_height_max (m2); i++) {
00075 for (j = 0; j < mat_width_max (m2); j++)
00076 printf ("%.4f\t", m2[i][j]);
00077 printf ("\n");
00078 }
00079
00080 m1[1][1] = 7;
00081 m2[4][2] = -3;
00082
00083
00084 m3 = mat_new_inv (m4);
00085 it_printf ("\nm4 = \n#.4f\n", m4);
00086 it_printf ("\ninv(m4) = \n#.6f\n", m3);
00087
00088 m5 = mat_new_mul (m4, m3);
00089
00090
00091 it_printf ("\nm1 = #.4f\n\nm2 = #.4f\n\nm4 * m3 = \n#m\n", m1, m2, m5);
00092
00093 it_printf ("\nm4 = \n#.6f\n", m4);
00094
00095 m6 = mat_new_transpose (m4);
00096 it_printf ("\ntranspose( m4 ) = \n#.6f\n", m6);
00097
00098
00099 mat_gs (m4);
00100 it_printf ("\ngram_schmidt : \n#.6f\n", m4);
00101
00102
00103 mat_cols_normalize (m4, 2);
00104 it_printf ("\nnormalize : \n#.6f\n", m4);
00105
00106
00107 it_printf ("\nmax : %f\n", mat_max (m4));
00108
00109
00110 m7 = mat_new (K, K);
00111 for (i = 0; i < K; i++)
00112 for (j = 0; j < K; j++)
00113 m7[i][j] = pow (0.5, fabs (j - i));
00114
00115 m8 = mat_new_inv (m7);
00116
00117 mat_delete (m1);
00118 mat_delete (m2);
00119 mat_delete (m3);
00120 mat_delete (m4);
00121 mat_delete (m5);
00122 mat_delete (m6);
00123 mat_delete (m7);
00124 mat_delete (m8);
00125 return 0;
00126 }