Fortran Coder

查看: 9154|回复: 8
打印 上一主题 下一主题

[数学库] 使用MKL库函数ZGETRS计算线性复方程组结果不对,小白求指导

[复制链接]

954

帖子

0

主题

0

精华

大师

F 币
184 元
贡献
75 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
楼主
发表于 2018-9-13 15:12:07 | 显示全部楼层
看如下代码之注释
[Fortran] 纯文本查看 复制代码
program main
  use f95_precision
  use lapack95
  implicit none
  integer :: i, j, n, info
  integer,allocatable:: ipiv(:)!// ipiv 为整数
  complex(8), allocatable :: a(:,:), b(:,:)
  n = 3
  allocate( ipiv(n) )
  allocate( a(n,n),  b(n,1) )
  a = 0.0
  open (5, file='a.txt', status='old') ! input file
  do j=1,n
    do i=1,n
      read(5,*) a(j,i)!//a转置
    enddo
  enddo
  !a = transpose(a)!//或者这样转置
  b = 0.0
  open (6, file='b.txt', status='old') ! input file
  do i=1,n
    read(6,*) b(i,1)
  enddo
  write(*,*)
  write(*,*)'matrix a : '
  do i=1,n;
    write(*,*) (a(i,:));
  enddo
  write(*,*)
  write(*,*)'matrix b : '
  do i=1,n;
    write(*,*) (b(i,1));
  enddo
  !call zgetrs( 'n', n, 1, a, n, ipiv, b, n, info )
  call getrf(a,ipiv,info)!//先 getrf
  call getrs(a,ipiv,b,'n',info) !//后 getrs
  write(*,*)
  write(*,*)'matrix b : '
  do i=1,n;
    write(*,*) (b(i,1));
  enddo
  write(*,*) info
end program main

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-17 10:34

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表