PartIIIIMSL数值分析程序库.docx
《PartIIIIMSL数值分析程序库.docx》由会员分享,可在线阅读,更多相关《PartIIIIMSL数值分析程序库.docx(86页珍藏版)》请在冰豆网上搜索。
PartIIIIMSL数值分析程序库
数值分析程序设计
PartIIIIMSL数值分析函数库
数值方法中常遇到的问题,有专门的函数链接库可以使用。
IMSL是一套在数值方法上经常被使用的商业函数链接库。
VisualFortran的专业版内含IMSL。
IMSL的函数名称中,第一个字母可以用来判断参数的类型。
如果第一个字母是D会使用双精度浮点数来计算并返回答案。
第一个字母不是D,则使用单精度浮点数计算。
为准确理解函数中各参数的意义和功能,下面的函数介绍采用英文原文。
必要时增加中文注释。
0IMSL函数库
TheIMSLLibraries
IMSL函数库包含两个独立部分:
∙MATH/LIBRARYgeneralappliedmathematicsandspecialfunctions
(应用数学和特殊函数函数库)
∙STAT/LIBRARYstatistics(统计函数库)
TheIMSLMATH/LIBRARYUser’sManualhastwoparts:
MATH/LIBRARYandMATH/LIBRARYSpecialFunctions.
Mostoftheroutinesareavailableinbothsingleanddoubleprecisionversions.Thesameuserinterfaceisfoundonthemanyhardwareversionsthatspantherangefrompersonalcomputertosupercomputer.NotethatsomeIMSLroutinesarenotdistributedforFORTRANcompilerenvironmentsthatdonotsupportdoubleprecisioncomplexdata.
ThenamesoftheIMSLroutinesthatreturnoracceptthetypedoublecomplexbeginwiththeletter“Z”and,occasionally,“DC.”
GettingStarted
TheIMSLMATH/LIBRARYisacollectionofFORTRANroutinesandfunctionsusefulinresearchandmathematicalanalysis.
Touseanyoftheseroutines,youmustwriteaprograminFORTRAN(orpossiblysomeotherlanguage)tocalltheMATH/LIBRARYroutine.(使用IMSL函数库必须编写Fortran程序调用相应的子程序)
在Fortran安装目录的DF98\IMSL\Help目录下提供PDF版本IMSL帮助文件MATH.pdf和F9040.pdf。
前者为IMSL数学分析函数库帮助文件,后者为Fortran90新增的一些函数库帮助文件。
需要IMSL使用的详细情况,请查阅帮助文件。
1线性系统(LinearSystems)
IMSL提供了大量的求解线性方程组的函数,可以用于求解数值分析中常见的各种问题。
例如,线性方程求解的直接法和迭代法、逆矩阵和行列式计算、最小二乘拟和问题、三角矩阵问题、矩阵的QR分解、奇异值分解和Cholesky分解等。
可以处理一般矩阵、对称矩阵、复矩阵、三角矩阵等的数值分析计算问题。
1.1线性系统求解、逆矩阵与行列式计算
1.1.1高精度线性系统求解——LSARG/DLSARG(Single/Doubleprecision)
功能:
Solvearealgeneralsystemoflinearequationswithiterativerefinement.
语法:
CALLLSARG(N,A,LDA,B,IPATH,X)
参数:
N—Numberofequations.(Input)(方程个数)
A—NbyNmatrixcontainingthecoefficientsofthelinearsystem.(Input)(系数矩阵)
LDA—LeadingdimensionofAexactlyasspecifiedinthedimensionstatementofthecallingprogram.(Input)(调用程序所需要的矩阵主维数——一般为矩阵行数)
B—VectoroflengthNcontainingtheright-handsideofthelinearsystem.(Input)(方程右边矩阵向量)
IPATH—Pathindicator.(Input)(求解指示器)
IPATH=1meansthesystemAX=Bissolved.
IPATH=2meansthesystemA7X=Bissolved.
X—VectoroflengthNcontainingthesolutiontothelinearsystem.(Output)(求解的未知量向量)
算法:
RoutineLSARGsolvesasystemoflinearalgebraicequationshavingarealgeneralcoefficientmatrix.ItfirstusestheroutineLFCRG,tocomputeanLUfactorizationofthecoefficientmatrixandtoestimatetheconditionnumberofthematrix.ThesolutionofthelinearsystemisthenfoundusingtheiterativerefinementroutineLFIRG.(LU分解法加上迭代改进解的精度)
算例:
求解线性方程组
programmain
useIMSL
!
Declarevariables
PARAMETER(IPATH=1,LDA=3,N=3)
REALA(LDA,LDA),B(N),X(N)
!
SetvaluesforAandB
!
A=(33.016.072.0)
!
(-24.0-10.0-57.0)
!
(18.0-11.07.0)
!
B=(129.0-96.08.5)
DATAA/33.0,-24.0,18.0,16.0,-10.0,-11.0,72.0,-57.0,7.0/
DATAB/129.0,-96.0,8.5/
CALLLSARG(N,A,LDA,B,IPATH,X)
write(*,*)x
END
1.1.2求解线性方程组——LSLRG/DLSLRG(Single/Doubleprecision)
功能:
Solvearealgeneralsystemoflinearequationswithoutiterativerefinement.
Usage:
CALLLSLRG(N,A,LDA,B,IPATH,X)
参数:
同上
算法:
RoutineLSLRGsolvesasystemoflinearalgebraicequationshavingarealgeneralcoefficientmatrix.ItfirstusestheroutineLFCRGtocomputeanLUfactorizationofthecoefficientmatrixbasedonGausseliminationwithpartialpivoting.
上一算例的计算结果:
1.1.3LU分解和矩阵条件数——LFCRG/DLFCRG
功能:
ComputetheLUfactorizationofarealgeneralmatrixandestimateitsL1conditionnumber.
语法:
CALLLFCRG(N,A,LDA,FAC,LDFAC,IPVT,RCOND)
参数:
N—Orderofthematrix.(Input)
A—NbyNmatrixtobefactored.(Input)
LDA—LeadingdimensionofAexactlyasspecifiedinthedimensionstatementofthecallingprogram.(Input)
FAC—NbyNmatrixcontainingtheLUfactorizationofthematrixA.(Output)IfAisnotneeded,AandFACcansharethesamestoragelocations.
LDFAC—LeadingdimensionofFACexactlyasspecifiedinthedimensionstatementofthecallingprogram.(Input)
IPVT—VectoroflengthNcontainingthepivotinginformationfortheLUfactorization.(Output)
RCOND—ScalarcontaininganestimateofthereciprocaloftheL1conditionnumberofA.(Output)
算法:
RoutineLFCRGperformsanLUfactorizationofarealgeneralcoefficientmatrix.Italsoestimatestheconditionnumberofthematrix.TheLUfactorizationisdoneusingscaledpartialpivoting.Scaledpartialpivotingdiffersfrompartialpivotinginthatthepivotingstrategyisthesameasifeachrowwerescaledtohavethesame∞-norm.
programmain
useIMSL
PARAMETER(IPATH=1,LDA=3,LDFAC=3,N=3)
INTEGERIPVT(N),J,NOUT
REALA(LDA,LDA),AINV(LDA,LDA),FAC1(LDFAC,LDFAC),RCOND
DATAA/1.0,1.0,1.0,3.0,3.0,4.0,3.0,4.0,3.0/
CALLLFCRG(N,A,LDA,FAC1,LDFAC,IPVT,RCOND)
CALLUMACH(2,NOUT)
write(*,*)"RCOND=,L1ConditionNumber="
WRITE(NOUT,"(2f8.4)")RCOND,1.0E0/RCOND
write(*,*)"Matrixa="
dok=1,3
write(*,*)a(k,1:
3)
enddo
write(*,*)"MatrixU="
dok=1,3
write(*,*)fac1(k,1:
3)
enddo
END
程序执行结果:
1.1.4LU分解求解线性方程组——LFSRG/DLFSRG
功能:
SolvearealgeneralsystemoflinearequationsgiventheLUfactorizationofthecoefficientmatrix.
语法:
CALLLFSRG(N,FAC,LDFAC,IPVT,B,IPATH,X)
参数:
N—Numberofequations.(Input)
FAC—NbyNmatrixcontainingtheLUfactorizationofthecoefficientmatrixAasoutputfromroutineLFCRG(Input)
LDFAC—LeadingdimensionofFACexactlyasspecifiedinthedimensionstatementofthecallingprogram.(Input)
IPVT—VectoroflengthNcontainingthepivotinginformationfortheLUfactorizationofAasoutputfromsubroutineLFCRG(page15)orLFTRG/DLFTRG(Input)
B—VectoroflengthNcontainingtheright-handsideofthelinearsystem.(Input)
IPATH—Pathindicator.(Input)
IPATH=1meansthesystemAX=Bissolved.
IPATH=2meansthesystemA7X=Bissolved.
X—VectoroflengthNcontainingthesolutiontothelinearsystem.(Output)IfBisnotneeded,BandXcansharethesamestoragelocations.
算法:
RoutineLFSRGcomputesthesolutionofasystemoflinearalgebraicequationshavingarealgeneralcoefficientmatrix.Tocomputethesolution,thecoefficientmatrixmustfirstundergoanLUfactorization.ThismaybedonebycallingeitherLFCRG,page15,orLFTRG,page18.ThesolutiontoAx=bisfoundbysolvingthetriangularsystemsLy=bandUx=y.TheforwardeliminationstepconsistsofsolvingthesystemLy=bbyapplyingthesamepermutationsandeliminationoperationstobthatwereappliedtothecolumnsofAinthefactorizationroutine.ThebackwardsubstitutionstepconsistsofsolvingthetriangularsystemUx=yforx.
求矩阵的逆矩阵
programmain
useIMSL
PARAMETER(IPATH=1,LDA=3,LDFAC=3,N=3)
INTEGERI,IPVT(N),J
REALA(LDA,LDA),AINV(LDA,LDA),FAC1(LDFAC,LDFAC),RJ(N)
DATAA/1.0,1.0,1.0,3.0,3.0,4.0,3.0,4.0,3.0/
CALLLFTRG(N,A,LDA,FAC1,LDFAC,IPVT)
CALLSSET(N,0.0,RJ,1)
DO10J=1,N
RJ(J)=1.0
CALLLFSRG(N,FAC1,LDFAC,IPVT,RJ,IPATH,AINV(1,J))
RJ(J)=0.0
10CONTINUE
dok=1,3
write(*,*)ainv(k,1:
3)
enddo
END
1.1.5计算矩阵行列式——LFDRG/DLFDRG
功能:
ComputethedeterminantofarealgeneralmatrixgiventheLUfactorizationofthematrix.
语法:
CALLLFDRG(N,FAC,LDFAC,IPVT,DET1,DET2)
参数:
N—Orderofthematrix.(Input)
FAC—NbyNmatrixcontainingtheLUfactorizationofthematrixAasoutputfromroutineLFCRG/DLFCRG(page15).(Input)
LDFAC—LeadingdimensionofFACexactlyasspecifiedinthedimensionstatementofthecallingprogram.(Input)
IPVT—VectoroflengthNcontainingthepivotinginformationfortheLUfactorizationasoutputfromroutineLFTRG/DLFTRGorLFCRG/DLFCRG.(Input)
DET1—Scalarcontainingthemantissaofthedeterminant.(Output)ThevalueDET1isnormalizedsothat1.0£|DET1|<10.0orDET1=0.0.
DET2—Scalarcontainingtheexponentofthedeterminant.(Output)Thedeterminantisreturnedintheformdet(A)=DET1*10DET2.
算法:
RoutineLFDRGcomputesthedeterminantofarealgeneralcoefficientmatrix.Tocomputethedeterminant,thecoefficientmatrixmustfirstundergoanLUfactorization.ThismaybedonebycallingeitherLFCRG(page15)orLFTRG(page18).TheformuladetA=detLdetUisusedtocomputethedeterminant.
programmain
useIMSL
PARAMETER(LDA=3,LDFAC=3,N=3)
INTEGERIPVT(N),NOUT
REALA(LDA,LDA),DET1,DET2,FAC1(LDFAC,LDFAC)
DATAA/33.0,-24.0,18.0,16.0,-10.0,-11.0,72.0,-57.0,7.0/
CALLLFTRG(N,A,LDA,FAC1,LDFAC,IPVT)
CALLLFDRG(N,FAC1,LDFAC,IPVT,DET1,DET2)
CALLUMACH(2,NOUT)
WRITE(NOUT,*)DET1,"*10**",DET2
END
程序执行结果:
1.1.6求矩阵的逆矩阵——LINRG/DLINRG
功能:
Computetheinverseofarealgeneralmatrix.
语法:
CALLLINRG(N,A,LDA,AINV,LDAINV)
参数:
N—OrderofthematrixA.(Input)
A—NbyNmatrixcontainingthematrixtobeinverted.(Input)
LDA—LeadingdimensionofAexactlyasspecifiedinthedimensionstatementofthecallingprogram.(Input)
AINV—NbyNmatrixcontainingtheinverseofA.(Output)IfAisnotneeded,AandAINVcansharethesamestoragelocations.
LDAINV—LeadingdimensionofAINVexactlyasspecifiedinthedimensionstatementofthecallingprogram.(Input)
算法:
RoutineLINRGcomputestheinverseofarealgeneralmatrix.ItfirstusestheroutineLFCRG(page15)tocomputeanLUfactorizationofthecoefficientmatrixandtoestimatetheconditionnumberofthematrix.RoutineLFCRGcomputesUandtheinformationneededtocomputeL-1.LINRT,page49,isthenusedtocomputeU-1.Finally,A-1iscomputedusingA-1=U-1L-1.
programmain
useIMSL
!
Declarevariables
PARAMETER(LDA=3,LDAINV=3,N=3)
INTEGERI,J,NOUT
REALA(LDA,LDA),AINV(LDAINV,LDAINV)
!
Setvaluesf