----------------------------------------------------------------------------------
@MSGID:
<f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com> c559ed72
@REPLYADDR Farzad Tatar
<tatarfarzad1992@gmail.com>
@REPLYTO 2:5075/128 Farzad Tatar
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID:
<f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
@TZUTC: -0700
@PID: G2/1.0
@TID: FIDOGATE-5.12-ge4e8b94
DEAR ALL,
I am trying to use LAPack libraries in Fortran to invert a square
matrix. I am new in Fortran and also LAPack. To rely on the results after
the inversion, I used a simple 2-2 matrix to check if I used the
subroutine correctly. However, I am receiving the wrong results. Here is the
code.
real(DP):: TEST(2,2) = TRANSPOSE(reshape((/1,2,3,4/), (/2,2/)))
real(DP):: TEST2(2) = (/1,2/)
PRINT*, `TEST , TEST2 ARE:`, TEST, TEST2
CALL DGESV(2, 1, TEST, 2, IPIV, TEST2, 2, INFO)
PRINT*, `AFTER THE INVERSION, TEST and TEST2 ARE:`, TEST, TEST2
In the output, I get this:
TEST , TEST2 ARE: 1.00000000000000 3.00000000000000
2.00000000000000 4.00000000000000 1.00000000000000
2.00000000000000
AFTER THE INVERSION, TEST , TEST2 ARE: 3.00000000000000
0.333333333333333 4.00000000000000 0.666666666666667
0.000000000000000E+000 0.500000000000000
while it should be this, Test inv=(/-2, 1, 1.5, -0.5/).
For the following input, however, the result is ok, even though
TEST after inversion is still the same.
real(DP):: TEST(2,2) = TRANSPOSE(reshape((/1,0,0,3/), (/2,2/)))
real(DP):: TEST2(2) = (/1,6/)
output:
TEST , TEST2 ARE: 1.00000000000000 0.000000000000000E+000
0.000000000000000E+000 3.00000000000000 1.00000000000000
6.00000000000000
AFTER THE INVERSION, TEST , TEST2 ARE: 1.00000000000000
0.000000000000000E+000 0.000000000000000E+000 3.00000000000000
1.00000000000000 2.00000000000000
Thank you in advance for your help.
Cheers,
Farzad Tatar
--- G2/1.0
* Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441