Cè¨èªããLAPACKã®zgeevãå¼ãã§è¤ç´ è¡åã対è§å
/* * SIZE*SIZEåã®è¤ç´ è¡åã®åºæå¤ã¨åºæãã¯ãã«ãè¨ç® * (1 2i) * (i 1+i) */ #define SIZE 2 // 2*2åã®è¡å #include <stdio.h> #include <complex.h> int main(void) { char jobvl = 'N' ;// å·¦åºæãã¯ãã«ã¯è¨ç®ããªã char jobvr = 'V' ;// å³åºæãã¯ãã«ã¯è¨ç®ãã int n = SIZE ;// 対è§åããæ£æ¹è¡åã®ãµã¤ãº double _Complex A[SIZE*SIZE] ;// 対è§åããè¡å A[0]=1; A[2]=2*I; A[1]=I; A[3]=1+I; int lda = SIZE ;// 対è§åããæ£æ¹è¡åã®ãµã¤ãº double _Complex wr[SIZE] ;// åºæå¤ãå ¥ã double _Complex vlDUMMY[1] ;// å·¦åºæãã¯ãã«ãå ¥ã(ä¸å¿ è¦ãªã®ã§[1]) int ldvlDUMMY = 1 ;// vlDUMMY[1]ã®æ¬¡å double _Complex vr[SIZE*SIZE] ;// å³åºæãã¯ãã«ãå ¥ã int ldvr = SIZE ;// å³åºæãã¯ãã«ã®æ¬æ° double _Complex work[2*SIZE] ;// 対è§åããéã«ä½¿ç¨ããã¡ã¢ãª int lwork = 2*SIZE ;// workã®æ¬¡å double rwork[2*SIZE] ;// 2*SIZEã§åºå® int info ;// æåããã°0 失æããã°0以å¤ãè¿ã // LAPACKã®zgeevãµãã«ã¼ãã³ãå¼ã¶ // å¼æ°ã¯å ¨ã¦åç §æ¸¡ã zgeev_(&jobvl, &jobvr, &n, A, &lda, wr, vlDUMMY, &ldvlDUMMY, vr, &ldvr, work, &lwork, rwork, &info); // 1çªç®ã®åºæãã¯ãã« : (vr[0] vr[1]) // 2çªç®ã®åºæãã¯ãã« : (vr[2] vr[3]) printf("1çªç®ã®åºæå¤:%5.3lf %+5.3lf*I\n", creal(wr[0]), cimag(wr[0])); printf("1çªç®ã®åºæãã¯ãã«:(%5.3lf %+5.3lf*I %5.3lf %+5.3lf*I)\n", creal(vr[0]), cimag(vr[0]), creal(vr[1]), cimag(vr[1])); printf("2çªç®ã®åºæå¤:%5.3lf %+5.3lf*I\n", creal(wr[1]), cimag(wr[1])); printf("2çªç®ã®åºæãã¯ãã«:(%5.3lf %+5.3lf*I %5.3lf %+5.3lf*I)\n", creal(vr[2]), cimag(vr[2]), creal(vr[3]), cimag(vr[3])); return 0; }
ã³ã³ãã¤ã«ã¨å®è¡çµæ
$ gcc hoge.c -llapack -lblas -lm $ ./a.out 1çªç®ã®åºæå¤:1.000 -1.000*I 1çªç®ã®åºæãã¯ãã«:(0.894 +0.000*I -0.447 -0.000*I) 2çªç®ã®åºæå¤:1.000 +2.000*I 2çªç®ã®åºæãã¯ãã«:(0.707 +0.000*I 0.707 -0.000*I)
å¼æ°ã®è©³ç´°ã«ã¤ãã¦ã¯ãä¸æãªè§£èª¬ãè¦ããã zgeev.f ã® Arguments ãèªãã®ãä¸çªããããããã
Cã¨Fortranã§è¡åã®æ·»åãç°ãªãç¹ã¸ã®æ³¨æåèµ·
Cè¨èª
Cè¨èªã®äºæ¬¡å
é
å A[3][3]
ã¨ã¯ã¤ã¾ã
A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2] A[2][0] ...
ã®é ã«ä¸¦ãã ä¸æ¬¡å é åãã®ãã®ã Cè¨èªã®é åæ·»åã¯0ã¹ã¿ã¼ãã ã å¾ã£ã¦ãCã®æ¨æºçãªäºæ¬¡å è¡åã®è¡¨ç¤ºã¯
( A[0][0] A[0][1] A[0][2] ) ( A[0] A[1] A[2] ) ( A[1][0] A[1][1] A[1][2] ) = ( A[3] A[4] A[5] ) ( A[2][0] A[2][1] A[2][2] ) ( A[6] A[7] A[8] )
Fortran
Fortranã®äºæ¬¡å
é
å A(3,3)
ã¨ã¯ã¤ã¾ã
A(1,1) A(2,1) A(3,1) A(1,2) A(2,2) A(3,2) A(1,3) ...
ã®é ã«ä¸¦ãã ä¸æ¬¡å é åãã®ãã®ã Fortranã®é åæ·»åã¯1ã¹ã¿ã¼ãã ã å¾ã£ã¦ãFortranã®æ¨æºçãªäºæ¬¡å è¡åã®è¡¨ç¤ºã¯
( A(1,1) A(1,2) A(1,3) ) ( A(1) A(4) A(7) ) ( A(2,1) A(2,2) A(2,3) ) = ( A(2) A(5) A(8) ) ( A(3,1) A(3,2) A(3,3) ) ( A(3) A(6) A(9) )
æ°å¦
æ°å¦ã®é åæ·»åã¯ãã¾ã大æµã®å ´å1ã¹ã¿ã¼ãã ã äºæ¬¡å è¡åã®æ°å¦çãªè¡¨ç¤ºã¯
a_{11} a_{12} a_{13} a_{21} a_{22} a_{23} a_{31} a_{32} a_{33}
çµå±ã©ã¼ããã®
åéã®ãããããã¨ã¯ãã¤ã¾ã
ãæ°å¦çãªäºæ¬¡å
è¡åã®{i,j}æåaijãã
ãCè¨èªã®ããã°ã©ã ãä¸ã§
ãFortranå¼æ·»åã®å¤æ°A(i,j)ã«è¨ç½®ããããã¨ã ã
ããã¯çµå±ä»¥ä¸ã®ããã«ããã°å®ç¾ã§ããã¨åããã ããã
A[0+0*2] = a11; A[1+0*2] = a12; A[2+0*2] = a13; A[0+1*2] = a21; A[1+1*2] = a22; A[2+1*2] = a23; A[0+2*2] = a31; A[1+2*2] = a32; A[2+2*2] = a33;
è¨æ£...ã³ã¡ã³ãã§ééããææããã¾ããããã¡ãçãã£ãã
/* Cè¨èªã§Fortranå½¢å¼ã®è¡åãä½ã * * æ°å¦çè¡å * a11 a12 a13 * a21 a22 a23 * a31 a32 a33 * * ãä¸æ¬¡å é å A[0] ... A[8] ã«å ¥ããã * A[(i-1)+(j-1)*3] ã« aij ãå ¥ããã°è¯ãã */ double _Complex A[3*3]; A[0+0*3] = a11; A[0+1*3] = a12; A[0+2*3] = a13; A[1+0*3] = a21; A[1+1*3] = a22; A[1+2*3] = a23; A[2+0*3] = a31; A[2+1*3] = a32; A[2+2*3] = a33;
2017/01/20 追è¨
zheevã®ä½¿ãæ¹ãæ¸ãã¾ããã auewe.hatenablog.com