Re: [問題] complex matrix 的 inverse matrix
※ 引述《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
08/16 04:30, 1F
→
08/16 05:19, , 2F
08/16 05:19, 2F
推
08/16 08:11, , 3F
08/16 08:11, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章