JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
matrix.cpp
Go to the documentation of this file.
1
7#include "matrix.h"
8
9
19{
20 vector c;
21 double r;
22
23 r = a.x*a.x+a.y*a.y+a.z*a.z;
24 if (Xabs(r)<EPS*EPS) {
25 c.x = 0.0;
26 c.y = 0.0;
27 c.z = 0.0;
28 c.n = 1.0;
29 }
30 else {
31 r = sqrt(r);
32 c.x = a.x/r;
33 c.y = a.y/r;
34 c.z = a.z/r;
35 c.n = 1.0;
36 }
37 return c;
38}
39
40
50{
51 vector c;
52 double r;
53
54 r = a.x*a.x+a.y*a.y+a.z*a.z;
55 if (Xabs(r)<EPS*EPS) {
56 c.x = 0.0;
57 c.y = 0.0;
58 c.z = 0.0;
59 c.n = 1.0;
60 }
61 else {
62 r = sqrt(r);
63 c.x = a.x/r;
64 c.y = a.y/r;
65 c.z = a.z/r;
66 c.n = 1.0;
67 }
68 return c;
69}
70
71
82vector set_vector(double x, double y, double z)
83{
84 vector c;
85
86 c.x = x;
87 c.y = y;
88 c.z = z;
89 c.n = sqrt(x*x + y*y + z*z);
90 return c;
91}
92
93
104ivector set_ivector(int x, int y, int z)
105{
106 ivector c;
107
108 c.x = x;
109 c.y = y;
110 c.z = z;
111 c.n = sqrt((double)x*x + y*y + z*z);
112 return c;
113}
114
115
126{
127 ivector c;
128
129 c.x = (int)(a.x + 0.5);
130 c.y = (int)(a.y + 0.5);
131 c.z = (int)(a.z + 0.5);
132 c.n = sqrt((double)c.x*c.x + c.y*c.y + c.z*c.z);
133 return c;
134}
135
136
146{
147 vector c;
148
149 c.x = (double)a.x;
150 c.y = (double)a.y;
151 c.z = (double)a.z;
152 c.n = sqrt(c.x*c.x + c.y*c.y + c.z*c.z);
153 return c;
154}
155
156
168{
169 vector c;
170
171 c.x = a.y*b.z - a.z*b.y;
172 c.y = a.z*b.x - a.x*b.z;
173 c.z = a.x*b.y - a.y*b.x;
174 c.n = sqrt(c.x*c.x+c.y*c.y+c.z*c.z);
175 return c;
176}
177
178
189{
190 int i;
191 matrix a;
192
193 a.n = a.r = 0;
194 a.mx = NULL;
195 a.sz = (int*)malloc(sizeof(int));
196 if (a.sz==NULL) return a;
197 a.sz[0] = n;
198
199 a.mx = (double*)malloc(n*sizeof(double));
200 if (a.mx==NULL) {
201 free(a.sz);
202 a.sz = NULL;
203 return a;
204 }
205
206 a.n = 1;
207 a.r = n;
208 for (i=0; i<n; i++) a.mx[i] = 0.0;
209 return a;
210}
211
212
223{
224 int i;
225 imatrix a;
226
227 a.n = a.r = 0;
228 a.mx = NULL;
229 a.sz = (int*)malloc(sizeof(int));
230 if (a.sz==NULL) return a;
231 a.sz[0] = n;
232
233 a.mx = (int*)malloc(n*sizeof(int));
234 if (a.mx==NULL) {
235 free(a.sz);
236 a.sz = NULL;
237 return a;
238 }
239
240 a.n = 1;
241 a.r = n;
242 for (i=0; i<n; i++) a.mx[i] = 0;
243 return a;
244}
245
246
257matrix make_matrix2(int n, int m)
258{
259 int i, s;
260 matrix a;
261
262 a.n = a.r = 0;
263 a.mx = NULL;
264 a.sz = (int*)malloc(2*sizeof(int));
265 if (a.sz==NULL) return a;
266 a.sz[0] = n;
267 a.sz[1] = m;
268 s = n*m;
269
270 a.mx = (double*)malloc(s*sizeof(double));
271 if (a.mx==NULL) {
272 free(a.sz);
273 a.sz = NULL;
274 return a;
275 }
276
277 a.n = 2;
278 a.r = s;
279 for (i=0; i<s; i++) a.mx[i] = 0.0;
280 return a;
281}
282
283
295{
296 int i, s;
297 imatrix a;
298
299 a.n = a.r = 0;
300 a.mx = NULL;
301 a.sz = (int*)malloc(2*sizeof(int));
302 if (a.sz==NULL) return a;
303 a.sz[0] = n;
304 a.sz[1] = m;
305 s = n*m;
306
307 a.mx = (int*)malloc(s*sizeof(int));
308 if (a.mx==NULL) {
309 free(a.sz);
310 a.sz = NULL;
311 return a;
312 }
313
314 a.n = 2;
315 a.r = s;
316 for (i=0; i<s; i++) a.mx[i] = 0;
317 return a;
318}
319
320
331matrix make_matrix(int n, int* sz)
332{
333 int i, s;
334 matrix a;
335
336 a.n = a.r = 0;
337 a.sz = (int*)malloc(n*sizeof(int));
338 if (a.sz==NULL) {
339 a.mx = NULL;
340 return a;
341 }
342 for (s=1,i=0; i<n; i++) {
343 a.sz[i] = sz[i];
344 s = s*sz[i];
345 }
346
347 a.mx = (double*)malloc(s*sizeof(double));
348 if (a.mx==NULL) {
349 free(a.sz);
350 a.sz = NULL;
351 return a;
352 }
353
354 a.n = n;
355 a.r = s;
356 for (i=0; i<s; i++) a.mx[i] = 0.0;
357 return a;
358}
359
360
371imatrix make_imatrix(int n, int* sz)
372{
373 int i, s;
374 imatrix a;
375
376 a.n = a.r = 0;
377 a.sz = (int*)malloc(n*sizeof(int));
378 if (a.sz==NULL) {
379 a.mx = NULL;
380 return a;
381 }
382 for (s=1,i=0; i<n; i++) {
383 a.sz[i] = sz[i];
384 s = s*sz[i];
385 }
386
387 a.mx = (int*)malloc(s*sizeof(int));
388 if (a.mx==NULL) {
389 free(a.sz);
390 a.sz = NULL;
391 return a;
392 }
393
394 a.n = n;
395 a.r = s;
396 for (i=0; i<s; i++) a.mx[i] = 0;
397 return a;
398}
399
400
409{
410 if(a->sz!=NULL) free(a->sz);
411 if(a->mx!=NULL) free(a->mx);
412 a->sz = NULL;
413 a->mx = NULL;
414 a->n = a->r = 0;
415}
416
417
426{
427 if(a->sz!=NULL) free(a->sz);
428 if(a->mx!=NULL) free(a->mx);
429 a->sz = NULL;
430 a->mx = NULL;
431 a->n = a->r = 0;
432}
433
434
449double* get_matrix(matrix mtx, ...)
450{
451 int m, d;
452 int* args;
453 va_list argsptr;
454
455 if (mtx.n<1) return NULL;
456 args = (int*)malloc(mtx.n*sizeof(int));
457 if (args==NULL) return NULL;
458
459 va_start(argsptr, mtx);
460 for (m=0; m<mtx.n; m++) {
461 args[m] = (int)va_arg(argsptr, int);
462 }
463 va_end(argsptr);
464
465 int dx = args[0] - 1;
466 for (d=1; d<mtx.n; d++) dx = dx*mtx.sz[d] + args[d] - 1;
467 free(args);
468
469 if (dx>=mtx.r || dx<0) return NULL;
470 return &mtx.mx[dx];
471}
472
473
488int* get_imatrix(imatrix mtx, ...)
489{
490 int m, d;
491 int* args;
492 va_list argsptr;
493
494 if (mtx.n<1) return NULL;
495 args = (int*)malloc(mtx.n*sizeof(int));
496 if (args==NULL) return NULL;
497
498 va_start(argsptr, mtx);
499 for (m=0; m<mtx.n; m++) {
500 args[m] = (int)va_arg(argsptr, int);
501 }
502 va_end(argsptr);
503
504 int dx = args[0] - 1;
505 for (d=1; d<mtx.n; d++) dx = dx*mtx.sz[d] + args[d] - 1;
506 free(args);
507
508 if (dx>=mtx.r || dx<0) return NULL;
509 return &mtx.mx[dx];
510}
511
512
524{
525 int i;
526
527 if (src.mx==NULL || dst.mx==NULL) return;
528 if ((src.r!=dst.r)||(dst.n!=dst.n)) return;
529
530 for (i=0; i<src.n; i++) dst.sz[i] = src.sz[i];
531 for (i=0; i<src.r; i++) dst.mx[i] = src.mx[i];
532}
533
534
546{
547 int i;
548
549 if (src.mx==NULL || dst.mx==NULL) return;
550 if ((src.r!=dst.r)||(dst.n!=dst.n)) return;
551
552 for (i=0; i<src.n; i++) dst.sz[i] = src.sz[i];
553 for (i=0; i<src.r; i++) dst.mx[i] = src.mx[i];
554}
555
556
568{
569 int i;
570 matrix c;
571
572 c.n = c.r = 0;
573 c.sz = NULL;
574 c.mx = NULL;
575 if (a.mx==NULL || b.mx==NULL) return c;
576 if (a.r != b.r) return c;
577
578 c = make_matrix(a.n, a.sz);
579 for (i=0; i<c.r; i++) c.mx[i] = a.mx[i] + b.mx[i];
580 return c;
581}
582
583
595{
596 int i;
597 imatrix c;
598
599 c.n = c.r = 0;
600 c.sz = NULL;
601 c.mx = NULL;
602 if (a.mx==NULL || b.mx==NULL) return c;
603 if (a.r != b.r) return c;
604
605 c = make_imatrix(a.n, a.sz);
606 for (i=0; i<c.r; i++) c.mx[i] = a.mx[i] + b.mx[i];
607 return c;
608}
609
610
622{
623 int i;
624 matrix c;
625
626 c.n = c.r = 0;
627 c.sz = NULL;
628 c.mx = NULL;
629 if (a.mx==NULL || b.mx==NULL) return c;
630 if (a.r != b.r) return c;
631
632 c = make_matrix(a.n, a.sz);
633 for (i=0; i<c.r; i++) c.mx[i] = a.mx[i] - b.mx[i];
634 return c;
635}
636
637
649{
650 int i;
651 imatrix c;
652
653 c.n = c.r = 0;
654 c.sz = NULL;
655 c.mx = NULL;
656 if (a.mx==NULL || b.mx==NULL) return c;
657 if (a.r != b.r) return c;
658
659 c = make_imatrix(a.n, a.sz);
660 for (i=0; i<c.r; i++) c.mx[i] = a.mx[i] - b.mx[i];
661 return c;
662}
663
664
676{
677 int i, j, k, n, ii, aa, bb;
678 int *sz, *sa, *sb, *sc, *cx;
679 double st;
680 matrix c;
681
682 c.n = c.r = 0;
683 c.sz = NULL;
684 c.mx = NULL;
685 if (a.mx==NULL || b.mx==NULL) return c;
686 if (a.sz[a.n-1]!=b.sz[0]) return c;
687
688 n = a.n + b.n - 2;
689 sz = (int*)malloc(n*sizeof(int));
690 if (sz==NULL) return c;
691 sa = (int*)malloc(a.n*sizeof(int));
692 if (sa==NULL) {free(sz); return c;}
693 sb = (int*)malloc(b.n*sizeof(int));
694 if (sb==NULL) {free(sz); free(sa); return c;}
695 sc = (int*)malloc(n*sizeof(int));
696 if (sc==NULL) {free(sz); free(sa); free(sb); return c;}
697 cx = (int*)malloc(n*sizeof(int));
698 if (cx==NULL) {free(sz); free(sa); free(sb); free(sc); return c;}
699
700 memset(sz, 0, n*sizeof(int));
701 memset(sa, 0, a.n*sizeof(int));
702 memset(sb, 0, b.n*sizeof(int));
703 memset(sc, 0, n*sizeof(int));
704 memset(cx, 0, n*sizeof(int));
705
706 for (i=0; i<a.n-1; i++) sz[i] = a.sz[i];
707 for (i=1; i<b.n; i++) sz[a.n-2+i] = b.sz[i];
708
709 sa[a.n-1] = sb[b.n-1] = sc[n-1] = 1;
710 for (i=a.n-2; i>=0; i--) sa[i] = sa[i+1]*a.sz[i+1];
711 for (i=b.n-2; i>=0; i--) sb[i] = sb[i+1]*b.sz[i+1];
712 for (i=n-2; i>=0; i--) sc[i] = sc[i+1]*sz[i+1];
713
714 c = make_matrix(n, sz);
715
716 for (i=0; i<c.r; i++) {
717 ii = i;
718 for (j=0; j<c.n; j++) {
719 cx[j] = ii / sc[j];
720 ii = ii % sc[j];
721 }
722 aa = bb = 0;
723 for (j=0; j<a.n-1; j++) aa = aa + sa[j]*cx[j];
724 for (j=1; j<b.n; j++) bb = bb + sb[j]*cx[j+a.n-2];
725
726 st = 0.0;
727 for (k=0; k<b.sz[0]; k++) st = st + a.mx[k+aa]*b.mx[bb+sb[0]*k];
728 c.mx[i] = st;
729 }
730
731 free(sz);
732 free(sa);
733 free(sb);
734 free(sc);
735 free(cx);
736
737 return c;
738}
739
740
752{
753 int i, j, k, n, ii, aa, bb, st;
754 int *sz, *sa, *sb, *sc, *cx;
755 imatrix c;
756
757 c.n = c.r = 0;
758 c.sz = NULL;
759 c.mx = NULL;
760 if (a.mx==NULL || b.mx==NULL) return c;
761 if (a.sz[a.n-1]!=b.sz[0]) return c;
762
763 n = a.n + b.n - 2;
764 sz = (int*)malloc(n*sizeof(int));
765 if (sz==NULL) return c;
766 sa = (int*)malloc(a.n*sizeof(int));
767 if (sa==NULL) {free(sz); return c;}
768 sb = (int*)malloc(b.n*sizeof(int));
769 if (sb==NULL) {free(sz); free(sa); return c;}
770 sc = (int*)malloc(n*sizeof(int));
771 if (sc==NULL) {free(sz); free(sa); free(sb); return c;}
772 cx = (int*)malloc(n*sizeof(int));
773 if (cx==NULL) {free(sz); free(sa); free(sb); free(sc); return c;}
774
775 memset(sz, 0, n*sizeof(int));
776 memset(sa, 0, a.n*sizeof(int));
777 memset(sb, 0, b.n*sizeof(int));
778 memset(sc, 0, n*sizeof(int));
779 memset(cx, 0, n*sizeof(int));
780
781 for (i=0; i<a.n-1; i++) sz[i] = a.sz[i];
782 for (i=1; i<b.n; i++) sz[a.n-2+i] = b.sz[i];
783
784 sa[a.n-1] = sb[b.n-1] = sc[n-1] = 1;
785 for (i=a.n-2; i>=0; i--) sa[i] = sa[i+1]*a.sz[i+1];
786 for (i=b.n-2; i>=0; i--) sb[i] = sb[i+1]*b.sz[i+1];
787 for (i=n-2; i>=0; i--) sc[i] = sc[i+1]*sz[i+1];
788
789 c = make_imatrix(n, sz);
790
791 for (i=0; i<c.r; i++) {
792 ii = i;
793 for (j=0; j<c.n; j++) {
794 cx[j] = ii / sc[j];
795 ii = ii % sc[j];
796 }
797 aa = bb = 0;
798 for (j=0; j<a.n-1; j++) aa = aa + sa[j]*cx[j];
799 for (j=1; j<b.n; j++) bb = bb + sb[j]*cx[j+a.n-2];
800
801 st = 0;
802 for (k=0; k<b.sz[0]; k++) st = st + a.mx[k+aa]*b.mx[bb+sb[0]*k];
803 c.mx[i] = st;
804 }
805
806 free(sz);
807 free(sa);
808 free(sb);
809 free(sc);
810 free(cx);
811
812 return c;
813}
814
815
824void print_matrix(FILE* fp, matrix a)
825{
826 int i;
827 for (i=0; i<a.r; i++) {
828 fprintf(fp, " %15lf", a.mx[i]);
829 if ((i+1)%a.sz[a.n-1]==0) fprintf(fp, "\n");
830 }
831// fprintf(stdout,"\n");
832}
833
834
843void print_imatrix(FILE* fp, imatrix a)
844{
845 int i;
846 for (i=0; i<a.r; i++) {
847 fprintf(fp, " %6d", a.mx[i]);
848 if ((i+1)%a.sz[a.n-1]==0) fprintf(fp, "\n");
849 }
850 fprintf(stdout,"\n");
851}
852
853
870{
871 int i, j, r, n, m, sz[2];
872 double s, t, u;
873 matrix nsq, isq, x, a;
874
875 a.n = a.r = 0;
876 a.sz = NULL;
877 a.mx = NULL;
878 if (xx.mx==NULL || col.mx==NULL) return a;
879 if (xx.n!=2 || (xx.sz[1]!=col.sz[0])) return a;
880
881 nsq.mx = isq.mx = x.mx = NULL;
882 n = xx.sz[0];
883 m = xx.sz[1];
884 sz[0] = sz[1] = m;
885 nsq = make_matrix(1, &m);
886 isq = make_matrix(1, &m);
887 x = make_matrix(xx.n, xx.sz);
888 a = make_matrix(xx.n, sz);
889 if (nsq.mx==NULL || isq.mx==NULL || x.mx==NULL || a.mx==NULL) {
890 free_matrix(&nsq);
891 free_matrix(&isq);
892 free_matrix(&x);
893 return a;
894 }
895
896 for (i=0; i<xx.r; i++) x.mx[i] = xx.mx[i];
897
898 for (i=1; i<=m; i++) {
899 for (s=0.0,j=1; j<=n; j++) s = s + Mx(x, j, i)*Mx(x, j, i);
900 Vt(nsq, i) = s;
901 Vt(isq, i) = ((Vt(nsq, i)!=0) ? Vt(nsq,i) : -1.0);
902 Vt(col, i) = i;
903 }
904
905 for (r=1; r<=m; r++) {
906 if (r!=1) {
907 j = r; u = 0.0;
908 for (i=r; i<=m; i++) {
909 t = Vt(nsq,i)/Vt(isq,i);
910 if (t>u) { u = t; j = i; }
911 }
912 i = Vt(col,j); Vt(col,j) = Vt(col,r); Vt(col,r) = i;
913 t = Vt(nsq,j); Vt(nsq,j) = Vt(nsq,r); Vt(nsq,r) = t;
914 t = Vt(isq,j); Vt(isq,j) = Vt(isq,r); Vt(isq,r) = t;
915 for (i=1; i<=n; i++) {
916 t = Mx(x,i,j);
917 Mx(x,i,j) = Mx(x,i,r);
918 Mx(x,i,r) = t;
919 }
920 }
921
922 for (u=0.0,i=r; i<=n; i++) u = u + Mx(x,i,r)*Mx(x,i,r);
923 u = sqrt(u);
924 if (Mx(x,r,r)<0.0) u = -u;
925 Mx(x, r, r) = Mx(x,r,r) + u;
926 t = 1.0/(Mx(x,r,r)*u);
927
928 for (j=1; j<=r-1; j++) Mx(x,r,j)=0.0;
929 for (j=r+1; j<=m; j++) {
930 for (s=0.0,i=r; i<=n; i++) s = s + Mx(x,i,r)*Mx(x,i,j);
931 for (i=r; i<=n; i++) Mx(x,i,j) = Mx(x,i,j) - s*t*Mx(x,i,r);
932 }
933 Mx(x,r,r) = -u;
934 }
935
936 for (i=1; i<=m; i++) {
937 for (j=1; j<=m; j++) Mx(a,i,j) = Mx(x,i,j);
938 }
939
940 free_matrix(&nsq);
941 free_matrix(&isq);
942 free_matrix(&x);
943
944 return a;
945}
946
947
968{
969 int i, m;
970 imatrix cl;
971 matrix rx, rt, rr, aa, bb, cc;
972
973 cc.n = cc.r = 0;
974 cc.sz = NULL;
975 cc.mx = NULL;
976 if (y.mx==NULL || x.mx==NULL) return cc;
977 if (y.sz[0]!=x.sz[0]) return cc;
978
979 //n = x.sz[0];
980 m = x.sz[1]; /* n×m 行列 n>=m */
981 cl = make_imatrix(1, &m);
982 if (cl.mx==NULL) return cc;
983 cc = make_matrix (1, &m);
984 if (cc.mx==NULL) {free_imatrix(&cl); return cc;}
985
986 rx = decompQR(x, cl);
987 rr = invrU_matrix(rx),
988 rt = mlt_matrix(rr, trans_matrix(rr));
989 aa = mlt_matrix(trans_matrix(x), y),
990 bb = mlt_matrix(rt, aa);
991
992 if (bb.mx!=NULL) for (i=0; i<m; i++) cc.mx[cl.mx[i]-1] = bb.mx[i];
993
994 free_imatrix(&cl);
995 free_matrix(&rx);
996 free_matrix(&rr);
997 free_matrix(&rt);
998 free_matrix(&aa);
999 free_matrix(&bb);
1000
1001 return cc;
1002}
1003
1004
1014{
1015 int i, j, k;
1016 matrix c;
1017 int sz[2];
1018
1019 c.n = c.r = 0;
1020 c.sz = NULL;
1021 c.mx = NULL;
1022 if (a.mx==NULL || a.n!=2) return c;
1023
1024 sz[0] = a.sz[1];
1025 sz[1] = a.sz[0];
1026 c = make_matrix(a.n, sz);
1027
1028 for (k=0; k<c.r; k++) {
1029 i = k/a.sz[1];
1030 j = k%a.sz[1];
1031 c.mx[j*sz[1]+i] = a.mx[k];
1032 }
1033 return c;
1034}
1035
1036
1046{
1047 int i, j, k, n;
1048 double t, u, det;
1049 matrix a;
1050
1051 a.n = a.r = 0;
1052 a.sz = NULL;
1053 a.mx = NULL;
1054 if (x.mx==NULL) return a;
1055 if (x.sz[0]!=x.sz[1]) return a;
1056
1057 n = x.sz[0]; // 上三角行列のチェック
1058 for (j=1; j<n; j++) {
1059 for (i=j+1; i<=n; i++) {
1060 if (Mx(x,i,j) != 0.0) return a;
1061 }
1062 }
1063
1064 det = 1.0;
1065 a = make_matrix(x.n, x.sz);
1066 if (a.mx==NULL) return a;
1067
1068 for (i=0; i<a.r; i++) a.mx[i] = x.mx[i];
1069
1070 for (k=1; k<=n; k++) {
1071 t = Mx(a,k,k);
1072 det = det*t;
1073 for (i=1; i<=n; i++) Mx(a,i,k) = Mx(a,i,k)/t;
1074 Mx(a,k,k) = 1.0/t;
1075
1076 for (j=1; j<=n; j++) {
1077 if (j!=k) {
1078 u = Mx(a,k,j);
1079 for (i=1; i<=n; i++) {
1080 if (i!=k) Mx(a,i,j) = Mx(a,i,j) - Mx(a,i,k)*u;
1081 else Mx(a,i,j) = - u/t;
1082 }
1083 }
1084 }
1085 }
1086 return a;
1087}
1088
#define Xabs(x)
Definition common.h:257
vector unit_vector(vector a)
Definition matrix.cpp:18
void print_imatrix(FILE *fp, imatrix a)
Definition matrix.cpp:843
void free_imatrix(imatrix *a)
Definition matrix.cpp:425
matrix make_matrix1(int n)
Definition matrix.cpp:188
vector unit_ivector(ivector a)
Definition matrix.cpp:49
matrix add_matrix(matrix a, matrix b)
Definition matrix.cpp:567
matrix sub_matrix(matrix a, matrix b)
Definition matrix.cpp:621
matrix minimum2(matrix y, matrix x)
Definition matrix.cpp:967
matrix make_matrix2(int n, int m)
Definition matrix.cpp:257
ivector f2ivector(vector a)
Definition matrix.cpp:125
ivector set_ivector(int x, int y, int z)
Definition matrix.cpp:104
vector i2vector(ivector a)
Definition matrix.cpp:145
vector ex_vector(vector a, vector b)
Definition matrix.cpp:167
vector set_vector(double x, double y, double z)
Definition matrix.cpp:82
double * get_matrix(matrix mtx,...)
Definition matrix.cpp:449
void copy_imatrix(imatrix src, imatrix dst)
Definition matrix.cpp:545
matrix decompQR(matrix xx, imatrix col)
Definition matrix.cpp:869
imatrix sub_imatrix(imatrix a, imatrix b)
Definition matrix.cpp:648
imatrix add_imatrix(imatrix a, imatrix b)
Definition matrix.cpp:594
void free_matrix(matrix *a)
Definition matrix.cpp:408
imatrix mlt_imatrix(imatrix a, imatrix b)
Definition matrix.cpp:751
imatrix make_imatrix2(int n, int m)
Definition matrix.cpp:294
matrix mlt_matrix(matrix a, matrix b)
Definition matrix.cpp:675
matrix make_matrix(int n, int *sz)
Definition matrix.cpp:331
void copy_matrix(matrix src, matrix dst)
Definition matrix.cpp:523
matrix invrU_matrix(matrix x)
Definition matrix.cpp:1045
imatrix make_imatrix(int n, int *sz)
Definition matrix.cpp:371
int * get_imatrix(imatrix mtx,...)
Definition matrix.cpp:488
matrix trans_matrix(matrix a)
Definition matrix.cpp:1013
void print_matrix(FILE *fp, matrix a)
Definition matrix.cpp:824
imatrix make_imatrix1(int n)
Definition matrix.cpp:222
マトリックス&ベクトルライブラリ ヘッダ
#define Mx(m, i, j)
2次元マトリックスの(i,j)要素を返す. 1から数える.
Definition matrix.h:84
#define Vt(m, i)
1次元マトリックスの i番目の要素を返す.1から数える.
Definition matrix.h:83
double EPS
Definition mt.cpp:9
int * sz
各次元の要素数 sz[0]?sz[n-1]
Definition matrix.h:56
int * mx
要素 mx[0]?mx[r-1]
Definition matrix.h:57
int n
次元数
Definition matrix.h:54
int r
全要素数 sz[0]+sz[1]+...+sz[n-1]
Definition matrix.h:55
int y
y方向成分
Definition matrix.h:23
int z
z方向成分
Definition matrix.h:24
int x
x方向成分
Definition matrix.h:22
double n
ベクトルの大きさ
Definition matrix.h:25
double * mx
要素 mx[0]?mx[r-1]
Definition matrix.h:72
int * sz
各次元の要素数 sz[0]?sz[n-1]
Definition matrix.h:71
int n
次元数
Definition matrix.h:69
int r
全要素数 sz[0]+sz[1]+...+sz[n-1]
Definition matrix.h:70
double z
z方向成分
Definition matrix.h:32
double y
y方向成分
Definition matrix.h:31
double n
ベクトルの大きさ
Definition matrix.h:33
double x
x方向成分
Definition matrix.h:30