请问如果我要用fortran求解一个二元一次线性方程组的话,应该调用IMSL函数库的哪个函数好
两个方程类似于a1*X+a2*Y=c1,b1*X+b2*Y=c2,a1,a1,b1,b2,c1,c2都是已知的实数...
两个方程类似于a1*X+a2*Y=c1,b1*X+b2*Y=c2,a1,a1,b1,b2,c1,c2都是已知的实数
展开
1个回答
展开全部
对IMSL不熟, 其实可以调用免费的LAPACK库中的dgesv函数, 下面是一个例子
================================
program test_dgesv
implicit none
real(8) :: a(3,3),b(3)
integer :: v(3),iflag,i
external dgesv
a=reshape([2.0,0.0,0.0,0.0,3.0,0.0,0.0,0.0,4.0],[3,3])
b=[20.0,33.0,48.0]
print*, 'a = '
do i = 1,3
print '(3(f14.8,x))',a(i,:)
end do
print*,'b = '
do i = 1,3
print '(f14.8)',b(i)
end do
call dgesv(3,1,a,3,v,b,3,iflag)
print*,'results = '
do i = 1,3
print '(f14.8)',b(i)
end do
stop
end program
================================
Linux下, 通常系统自带lapack.a静态库和lapack.so动态库, 则可以通过如下命令编译
$ ifort test_dgesv.f90 -L/usr/lib -llapack -o test_dgesv.exe
运行结果
a =
2.00000000 0.00000000 0.00000000
0.00000000 3.00000000 0.00000000
0.00000000 0.00000000 4.00000000
b =
20.00000000
33.00000000
48.00000000
results =
10.00000000
11.00000000
12.00000000
================================
program test_dgesv
implicit none
real(8) :: a(3,3),b(3)
integer :: v(3),iflag,i
external dgesv
a=reshape([2.0,0.0,0.0,0.0,3.0,0.0,0.0,0.0,4.0],[3,3])
b=[20.0,33.0,48.0]
print*, 'a = '
do i = 1,3
print '(3(f14.8,x))',a(i,:)
end do
print*,'b = '
do i = 1,3
print '(f14.8)',b(i)
end do
call dgesv(3,1,a,3,v,b,3,iflag)
print*,'results = '
do i = 1,3
print '(f14.8)',b(i)
end do
stop
end program
================================
Linux下, 通常系统自带lapack.a静态库和lapack.so动态库, 则可以通过如下命令编译
$ ifort test_dgesv.f90 -L/usr/lib -llapack -o test_dgesv.exe
运行结果
a =
2.00000000 0.00000000 0.00000000
0.00000000 3.00000000 0.00000000
0.00000000 0.00000000 4.00000000
b =
20.00000000
33.00000000
48.00000000
results =
10.00000000
11.00000000
12.00000000
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询