I am trying to solve a linear equation in Fortran using the DGESV subroutine in LAPACK:
I have the following code:
program main
implicit none (type, external)
external :: DGESV
real(kind=8) :: para_morse(3) ! Vector b/x.
real(kind=8) :: pi, delta, Xtop, Ytop, Dtop
real(kind=8) :: Xhollow, Yhollow, Dhollow
real(kind=8) :: Xbridge, Ybridge, Dbridge
real(kind=8) :: a00,a01,a02,a10,a11,a12,a20,a21,a22
INTEGER :: N, NRHS, LDA, LDB, INFO
INTEGER :: IPIVOT(3)
DOUBLE PRECISION :: A(3,3), B(3,1)
pi = 3.14159265359
delta = 3.17*10**(-10)
Xtop = 0
Ytop = 0
Dtop = 4.9984788
Xhollow = 0.5
Yhollow = 0.5
Dhollow = 7.60346595
Xbridge = 0.5
Ybridge = 0
Dbridge = 5.56938086
a00 = 1
a10 = 1
a20 = 1
a01 = (cos((2*pi*Xbridge)/delta) + cos((2*pi*Ybridge)/delta))
a11 = (cos((2*pi*Xtop)/delta) + cos((2*pi*Ytop)/delta))
a21 = (cos((2*pi*Xhollow)/delta) + cos((2*pi*Yhollow)/delta))
a02 = (cos((2*pi*(Xbridge+Ybridge))/delta) + cos((2*pi*(Xbridge-Ybridge))/delta))
a12 = (cos((2*pi*(Xtop+Ytop))/delta) + cos((2*pi*(Xtop-Ytop))/delta))
a22 = (cos((2*pi*(Xhollow+Yhollow))/delta) + cos((2*pi*(Xhollow-Yhollow))/delta))
A = reshape([ a00, a10, a20, a01, a11, a21, a02, a12, a22], [ 3, 3 ])
B = reshape([ Dbridge, Dtop, Dhollow], [ 3, 1 ])
N = 3
NRHS = 1
IPIVOT = 3
LDA = 3
LDB = 3
CALL DGESV(N, NRHS, A, LDA, IPIVOT, B, LDB, INFO)
if (info /= 0) then
print '(a, i0)', 'Error: ', info
stop
end if
print *, "Solution (x1, x2, x3): ", B
end program main
However, all my solutions are being displayed as NaN. I have solved the same equation using NumPy linalg.solve in python and I obtain the following result [ 7.6678536 -0.58501309 -31.07990139]. Can someone help me understand why I am getting NaN as the result?