fortran - 使用 SGETR(F,I) 的 Fortran 逆矩阵计算仅适用于单精度
问题描述
我正在尝试计算方阵的逆,但它不起作用。我检查了以前的帖子,但逻辑相同,但我仍然没有发现问题出在哪里。我还分享了 Matlab 结果,例如矩阵。
program test
Implicit none
real,allocatable,dimension(:,:) :: A
real,allocatable,dimension(:) :: WORK
integer ,allocatable,dimension(:) :: ipiv
integer :: n,info,M
external SGETRF,SGETRI
M=8
allocate(A(M,M),WORK(M),IPIV(M))
A(1,:)=(/3.74E-4, 0.0, 0.0, 4.98E-5, 0.0, 0.0, 0.0, 0.0/)
A(2,:)=(/0.0 , 3.74E-4, 0.0, 0.0, 4.98E-5 ,0.0 ,0.0 ,0.0 /)
A(3,:)=(/0.0 , 0.0 ,3.74E-4, 0.0 ,0.0, 4.98E-5, 0.0 ,0.0/)
A(4,:)=(/4.98E-5 ,0.0 ,0.0 ,6.64e-6, 0.0 ,0.0, 0.0, 0.0 /)
A(5,:)=(/0.0 , 4.98E-5, 0.0, 0.0 ,6.64E-6 ,0.0 ,0.0 ,0.0 /)
A(6,:)=(/0.0, 0.0, 4.98E-5, 0.0 ,0.0, 6.64E-6, 0.0 ,0.0 /)
A(7,:)=(/0.0, 0.0 ,0.0, 0.0 ,0.0 ,0.0 ,1.49E-11, 0.0 /)
A(8,:)=(/0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0, 0.0 ,1.49E-11 /)
call SGETRF(M,M,A,M,IPIV,info)
if(info .eq. 0) then
Print *,'succeded'
else
Print *,'failed'
end if
call SGETRI(M,A,M,IPIV,WORK,M,info)
if(info .eq. 0) then
Print *,'succeded'
else
Print *,'failed'
end if
Print *,A
deallocate(A,IPIV,WORK)
end
!!!!! Matlab Result
!1.0e+10 *
! 0.0002 0 0 -0.0015 0 0 0 0
! 0 0.0002 0 0 -0.0015 0 0 0
! 0 0 0.0002 0 0 -0.0015 0 0
! -0.0015 0 0 0.0113 0 0 0 0
! 0 -0.0015 0 0 0.0113 0 0 0
! 0 0 -0.0015 0 0 0.0113 0 0
! 0 0 0 0 0 0 6.7114 0
! 0 0 0 0 0 0 0 6.7114
解决方案
你reals
只是单精度。lapackD
前缀意味着双精度。两个修复:
- 将您的 s 更改
DG
为SG
s - 保留你
DG
的 s 并使用双精度
推荐阅读
- ubuntu - 如何使用 SNAP 安装 VSCode?ERROR= snap-confine 具有提升的权限
- git - 在集成 Jenkins 时我是否应该在 GIT 中有多个发布分支
- sql - SQL 查询返回 ID、办公室编号以及每年是否有该员工的发票
- codenameone - 代号一中从视频到图像
- php - 如何在 Laravel 6 中使用动态字段返回视图
- pandas - 使用 Pandas 的堆积条形图
- android - Android TV 无法访问互联网
- angular - 当另一个组件的输入值发生变化时,调用另一个组件的方法
- jquery - 如何在反应代码中转换这个 jQuery?
- c# - 连接到不安全的 gRPC 通道时“响应提前结束”