cfort
cfort

Reputation: 1301

Difference in Fortran and C array storage?

I want to compute qr decomposition using F77_NAME(dgeqrf) function from Lapack lib in a c program.

For the matrix 3x3 :

12.000000 -51.000000 4.000000
6.000000 167.000000 -68.000000
-4.000000 24.000000 -41.000000

I get the output 3x3 (a combination of R matrix and some vectors used to construct Q)(linear form) :

-52.545219, -0.790144, 0.061972, 165.895209, -70.906839, -0.520684, 27.328842, -31.566433, -23.015097

I use then F77_NAME(dorgqr) from Lapack to extract Q matrix, get the output 3x3 (linear form) :

-0.228375, 0.970593, -0.076125, -0.618929, -0.084383, 0.780901, 0.751513, 0.225454, 0.619999

This is an example taken from wikipedia and it seems my Q differs from the wikipedia Q : http://en.wikipedia.org/wiki/QR_decomposition#Example_2

Could the difference between fortran and c array representation be the cause? Would a transpose on the initial matrix solve the problem ?

Upvotes: 1

Views: 316

Answers (1)

gheorghe1800
gheorghe1800

Reputation: 251

I hope you don't expect others to do your work. Since you almost answered your question, I don't see the point in posting it. Also, it may be a good thing to do to take some time in reading the FAQ section of this site before using it. You might find some useful info there.

As for the answer to the question:

It most probably is indeed the difference in array representation between C and Fortran the reason for your problem. See this:

http://en.wikipedia.org/wiki/Row-major_order

For general information on mixing Fortran and C code, this might be helpful:

http://www.yolinux.com/TUTORIALS/LinuxTutorialMixingFortranAndC.html

Upvotes: 1

Related Questions