Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The universe is an island, surrounded by whatever it is that surrounds universes.


devel / comp.lang.fortran / DGESV LAPACK HELP

SubjectAuthor
* DGESV LAPACK HELPFarzad Tatar
+- Re: DGESV LAPACK HELPGiorgio Pastore
+- Re: DGESV LAPACK HELPgah4
`* Re: DGESV LAPACK HELPgah4
 `* Re: DGESV LAPACK HELPFarzad Tatar
  +- Re: DGESV LAPACK HELPgah4
  `- Re: DGESV LAPACK HELPgah4

1
DGESV LAPACK HELP

<f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=3560&group=comp.lang.fortran#3560

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ad4:4f54:0:b0:649:74d0:c0ba with SMTP id eu20-20020ad44f54000000b0064974d0c0bamr87955qvb.2.1693492295917;
Thu, 31 Aug 2023 07:31:35 -0700 (PDT)
X-Received: by 2002:a63:954a:0:b0:564:17ba:47cd with SMTP id
t10-20020a63954a000000b0056417ba47cdmr667468pgn.10.1693492295521; Thu, 31 Aug
2023 07:31:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 31 Aug 2023 07:31:34 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=160.78.21.136; posting-account=hxOrswoAAAA-EZ0m91Ex-Pg6IGNqw1Kv
NNTP-Posting-Host: 160.78.21.136
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
Subject: DGESV LAPACK HELP
From: tatarfarzad1992@gmail.com (Farzad Tatar)
Injection-Date: Thu, 31 Aug 2023 14:31:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2676
 by: Farzad Tatar - Thu, 31 Aug 2023 14:31 UTC

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

Re: DGESV LAPACK HELP

<klcia5FihqfU3@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=3563&group=comp.lang.fortran#3563

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: pastgio@units.it (Giorgio Pastore)
Newsgroups: comp.lang.fortran
Subject: Re: DGESV LAPACK HELP
Date: Fri, 1 Sep 2023 00:25:09 +0200
Lines: 13
Message-ID: <klcia5FihqfU3@mid.individual.net>
References: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net ojWUD68mbNnnuSJFtb0rXQc5B0bJw5tRpa0kLj1YOTLYjZoxZ7
Cancel-Lock: sha1:E50eqR1br4+ewydUq6HBLUUULN8= sha256:oZxu7QPBZ4OAD4wtuOzCOBPksI6dBbtiAPmFJxy9C1M=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.14.0
Content-Language: it
In-Reply-To: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
 by: Giorgio Pastore - Thu, 31 Aug 2023 22:25 UTC

Il 31/08/23 16:31, Farzad Tatar ha scritto:
> 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

You should be aware that dgesv doesn't invert a matrix. It solves a
linear system where test is the matrix of coefficients, and test2 the
array of the known terms. In aoutput test2 is the array containing the
solution.

Giorgio

Re: DGESV LAPACK HELP

<30e8fe19-14fc-46a0-9acc-a384fa844fcfn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=3565&group=comp.lang.fortran#3565

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:18c7:b0:64a:742c:dcbd with SMTP id cy7-20020a05621418c700b0064a742cdcbdmr18167qvb.1.1693526771623;
Thu, 31 Aug 2023 17:06:11 -0700 (PDT)
X-Received: by 2002:a17:90a:d518:b0:262:de4e:3967 with SMTP id
t24-20020a17090ad51800b00262de4e3967mr239741pju.0.1693526771019; Thu, 31 Aug
2023 17:06:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 31 Aug 2023 17:06:10 -0700 (PDT)
In-Reply-To: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:8838:f51c:e05:950c;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:8838:f51c:e05:950c
References: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <30e8fe19-14fc-46a0-9acc-a384fa844fcfn@googlegroups.com>
Subject: Re: DGESV LAPACK HELP
From: gah4@u.washington.edu (gah4)
Injection-Date: Fri, 01 Sep 2023 00:06:11 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2227
 by: gah4 - Fri, 1 Sep 2023 00:06 UTC

On Thursday, August 31, 2023 at 7:31:38 AM UTC-7, Farzad Tatar wrote:
> 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.

Looks to me like the answer is right.

It does not return the inverse in the third argument, but the LU
decomposition, not including the diagonal of L, which is all 1.

I am not fast enough doing LU by hand, to tell if it is right.
It does seem the LU for a diagonal matrix is the same, as you see.

But multiplying the original matrix by the result does give the
original values for TEST2.

It is, I believe, easy to get the actual inverse from LU, though.

You don't show the declaration or values for IPIV.
It will sometimes exchange the rows, which you will only know if
you show IPIV.

Re: DGESV LAPACK HELP

<4d061409-7c22-4e8c-a020-6e4476e8f165n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=3566&group=comp.lang.fortran#3566

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:64f:b0:40e:b4f2:b382 with SMTP id a15-20020a05622a064f00b0040eb4f2b382mr25968qtb.11.1693545998426;
Thu, 31 Aug 2023 22:26:38 -0700 (PDT)
X-Received: by 2002:a17:902:ce83:b0:1c2:b50:c91d with SMTP id
f3-20020a170902ce8300b001c20b50c91dmr633104plg.10.1693545997979; Thu, 31 Aug
2023 22:26:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 31 Aug 2023 22:26:37 -0700 (PDT)
In-Reply-To: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:8838:f51c:e05:950c;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:8838:f51c:e05:950c
References: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4d061409-7c22-4e8c-a020-6e4476e8f165n@googlegroups.com>
Subject: Re: DGESV LAPACK HELP
From: gah4@u.washington.edu (gah4)
Injection-Date: Fri, 01 Sep 2023 05:26:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1808
 by: gah4 - Fri, 1 Sep 2023 05:26 UTC

On Thursday, August 31, 2023 at 7:31:38 AM UTC-7, Farzad Tatar wrote:
> I am trying to use LAPack libraries in Fortran to invert a square matrix.
(snip)

> 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
Seems to me that there is an easy way to get the inverse matrix.

Set TEST2 to an identity matrix, and so the solution will be the inverse.

Re: DGESV LAPACK HELP

<be249762-6f1d-4b0d-8c37-bfd262721bd8n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=3567&group=comp.lang.fortran#3567

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:5846:0:b0:403:996b:1390 with SMTP id h6-20020ac85846000000b00403996b1390mr35587qth.11.1693553834447;
Fri, 01 Sep 2023 00:37:14 -0700 (PDT)
X-Received: by 2002:a05:620a:8ec6:b0:765:a4f2:51ec with SMTP id
rg6-20020a05620a8ec600b00765a4f251ecmr43281qkn.4.1693553834166; Fri, 01 Sep
2023 00:37:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 1 Sep 2023 00:37:13 -0700 (PDT)
In-Reply-To: <4d061409-7c22-4e8c-a020-6e4476e8f165n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=160.78.21.136; posting-account=hxOrswoAAAA-EZ0m91Ex-Pg6IGNqw1Kv
NNTP-Posting-Host: 160.78.21.136
References: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com> <4d061409-7c22-4e8c-a020-6e4476e8f165n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <be249762-6f1d-4b0d-8c37-bfd262721bd8n@googlegroups.com>
Subject: Re: DGESV LAPACK HELP
From: tatarfarzad1992@gmail.com (Farzad Tatar)
Injection-Date: Fri, 01 Sep 2023 07:37:14 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2657
 by: Farzad Tatar - Fri, 1 Sep 2023 07:37 UTC

>It does not return the inverse in the third argument, but the LU
>decomposition, not including the diagonal of L, which is all 1.

Thanks for telling me this, I had totally ignored this. probably this is the reason. I will check it out.
> Set TEST2 to an identity matrix, and so the solution will be the inverse.

Since the dimensions are not the same, i.e., I don't have two columns of unknowns, this solution will not help.

>You don't show the declaration or values for IPIV.
>It will sometimes exchange the rows, which you will only know if
>you show IPIV.

Here is one example of what I believed was not correct.

A. CODE:

real:: TEST(2,2) = TRANSPOSE(reshape((/1.,2.,3.,4./), (/2,2/)))
real:: TEST2(2) = (1.,1.)
integer :: ipiv2(2)
integer, parameter :: sizet=2
goto 999
....

999 NRHS=1
print*, 'before solving', test, test2
CALL DGESV(sizet, nrhs, TEST, sizet, IPIV2, TEST2, sizet, INFO)
print*, ' after solving:', test, test2
print*, ' ipiv2 vector: ' ipiv2

B. RESULTS IN CMD:
before solving 1.000000 3.000000 2.000000 4.000000
1.000000 1.000000
after solving: 2.000000 4.000000 -1.7014126E+38 1.375000
0.0000000E+00 0.0000000E+00
ipiv2 vector: 2 2
OUTPUTS OF SOLVING LS: INFO 0

C. WHILE I EXPECT THESE VALUES, YOU CAN PUT THEM IN THE EQUATION AND CHECK.
X1=-1, X2=1 BUT THE OUTPUT IS 0 AND 0.

Re: DGESV LAPACK HELP

<149cb9af-8fc6-42f1-8133-9446875657f6n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=3568&group=comp.lang.fortran#3568

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:4:b0:406:94da:5abd with SMTP id x4-20020a05622a000400b0040694da5abdmr41031qtw.12.1693559529745;
Fri, 01 Sep 2023 02:12:09 -0700 (PDT)
X-Received: by 2002:a17:90a:868c:b0:26d:68ca:439f with SMTP id
p12-20020a17090a868c00b0026d68ca439fmr399668pjn.7.1693559529554; Fri, 01 Sep
2023 02:12:09 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 1 Sep 2023 02:12:08 -0700 (PDT)
In-Reply-To: <be249762-6f1d-4b0d-8c37-bfd262721bd8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:49a2:3d66:d5e8:16e3;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:49a2:3d66:d5e8:16e3
References: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
<4d061409-7c22-4e8c-a020-6e4476e8f165n@googlegroups.com> <be249762-6f1d-4b0d-8c37-bfd262721bd8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <149cb9af-8fc6-42f1-8133-9446875657f6n@googlegroups.com>
Subject: Re: DGESV LAPACK HELP
From: gah4@u.washington.edu (gah4)
Injection-Date: Fri, 01 Sep 2023 09:12:09 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1763
 by: gah4 - Fri, 1 Sep 2023 09:12 UTC

On Friday, September 1, 2023 at 12:37:16 AM UTC-7, Farzad Tatar wrote:

(snip, I wrote)

> > Set TEST2 to an identity matrix, and so the solution will be the inverse.

> Since the dimensions are not the same, i.e., I don't have two columns of unknowns, this solution will not help.

You can have any number of columns of unknowns (greater than zero).
So, with a test2(2,2), you could have two columns and set nrhs to 2.

Re: DGESV LAPACK HELP

<e54a9d2d-7ae1-4e2b-ac8f-ddc6daf8d1f8n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=3569&group=comp.lang.fortran#3569

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:492:b0:76f:2631:caa3 with SMTP id 18-20020a05620a049200b0076f2631caa3mr41529qkr.2.1693562871689;
Fri, 01 Sep 2023 03:07:51 -0700 (PDT)
X-Received: by 2002:a05:6a00:2d0d:b0:68a:5937:ea87 with SMTP id
fa13-20020a056a002d0d00b0068a5937ea87mr892387pfb.3.1693562871096; Fri, 01 Sep
2023 03:07:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 1 Sep 2023 03:07:50 -0700 (PDT)
In-Reply-To: <be249762-6f1d-4b0d-8c37-bfd262721bd8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:49a2:3d66:d5e8:16e3;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:49a2:3d66:d5e8:16e3
References: <f8466a68-55d1-4d8c-a607-5c41c85404d2n@googlegroups.com>
<4d061409-7c22-4e8c-a020-6e4476e8f165n@googlegroups.com> <be249762-6f1d-4b0d-8c37-bfd262721bd8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e54a9d2d-7ae1-4e2b-ac8f-ddc6daf8d1f8n@googlegroups.com>
Subject: Re: DGESV LAPACK HELP
From: gah4@u.washington.edu (gah4)
Injection-Date: Fri, 01 Sep 2023 10:07:51 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: gah4 - Fri, 1 Sep 2023 10:07 UTC

On Friday, September 1, 2023 at 12:37:16 AM UTC-7, Farzad Tatar wrote:

(snip)

> real:: TEST(2,2) = TRANSPOSE(reshape((/1.,2.,3.,4./), (/2,2/)))
> real:: TEST2(2) = (1.,1.)
> integer :: ipiv2(2)
> integer, parameter :: sizet=2
> goto 999
> ...
>
> 999 NRHS=1
> print*, 'before solving', test, test2
> CALL DGESV(sizet, nrhs, TEST, sizet, IPIV2, TEST2, sizet, INFO)
> print*, ' after solving:', test, test2
> print*, ' ipiv2 vector: ' ipiv2

(snip)

DGESV needs double precision 3rd and 6th argument.

If you give it single precision, it will try to access, in this case,
four double precision variables in an array big enough for two.

The -1.7014126E+38 is the most negative single precision value
on many systems. That is a sign that something is wrong.

If you change to SGESV it should work.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor