Re: [問題] complex matrix 的 inverse matrix

看板Fortran作者 (aa)時間12年前 (2012/08/16 02:07), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《forentia (謹慎)》之銘言: : 請問各位大大 : 要怎麼算出complex matrix的反函數? : 網路上找到的是real的 : 那complex有辦法嗎? 剛剛好最近有用到, 直接po上來好了 program main implicit none complex*16::a(3,3),b(3,3),c(3,3) data a/10,2.5,(3,7),4,5,6,7,8,9/ print*,'a=' write(*,'(3(F8.4,"+i",F8.4,", "))') , a(1,:) write(*,'(3(F8.4,"+i",F8.4,", "))') , a(2,:) write(*,'(3(F8.4,"+i",F8.4,", "))') , a(3,:) b=zInverse(3,a) print*,'b=' write(*,'(3(F8.4,"+i",F8.4,", "))') , b(1,:) write(*,'(3(F8.4,"+i",F8.4,", "))') , b(2,:) write(*,'(3(F8.4,"+i",F8.4,", "))') , b(3,:) c=matmul(a,b) print*,'c=' write(*,'(3(F8.4,"+i",F8.4,", "))') , c(1,:) write(*,'(3(F8.4,"+i",F8.4,", "))') , c(2,:) write(*,'(3(F8.4,"+i",F8.4,", "))') , c(3,:) contains function zInverse(n, a) result(ra) integer::n,lda,ipiv(n),info,lwork complex*16::a(n,n),ra(n,n),work(n) ra=a lwork=n lda=n call zgetrf(n, n, ra, lda, ipiv, info) if(info/=0) write(0,*) 'Error occured in zgetrf!' call zgetri(n, ra, lda, ipiv, work, lwork, info) if(info/=0) write(0,*) 'Error occured in zgetri!' endfunction end --------------------------------------------- 其中zgetrf和zgetri是lapack的函數 前面的z可改成 s,d,c 分別對應到 s: Short-precision real d: Long-precision real c: Short-precision complex z: Long-precision complex 如果安裝的是比較新的版本的intel fortran compiler, intel MKL應該都會附在安裝檔裡面 http://software.intel.com/en-us/articles/non-commercial-software-download/ 非商業用版可以免費下載 在編譯要用到lapack的檔案的時候可以參考使用下面的方法 ifort example.f90 -L/{compiler安裝路徑}/mkl/lib/intel64 -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm 詳細的mkl link 可以參考下面網頁 http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/ 希望對你有幫助 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 36.237.169.160

08/16 04:30, , 1F
免費?我還以為只有LINUX版本才有非商業版免費說@@
08/16 04:30, 1F

08/16 05:19, , 2F
我說的也是指在Linux底下....
08/16 05:19, 2F

08/16 08:11, , 3F
新版 ifort -mkl 就可以了。
08/16 08:11, 3F
文章代碼(AID): #1GA-LosK (Fortran)
討論串 (同標題文章)
文章代碼(AID): #1GA-LosK (Fortran)