Fortran 和 C 数组存储的区别?
我想使用 ac 程序中 Lapack lib 中的 F77_NAME(dgeqrf) 函数来计算 qr 分解。
对于矩阵 3x3 :
12.000000 -51.000000 4.000000
6.000000 167.000000 -68.000000
-4.000000 24.000000 -41.000000
我得到输出 3x3 (R 矩阵和一些用于构造 Q 的向量的组合)(线性形式):
-52.545219, -0.790144, 0.061972, 165.895209, -70.906839, -0.520684, 27.328842, -31.566433, -23.015097
然后我使用 Lapack 中的 F77_NAME(dorgqr) 来提取 Q 矩阵,得到输出 3x3 (线性形式) ):
-0.228375, 0.970593, -0.076125, -0.618929, -0.084383, 0.780901, 0.751513, 0.225454, 0.619999
这是来自维基百科的示例,看来我的 Q 与维基百科的 Q 不同: http://en.wikipedia.org/wiki/QR_decomposition#Example_2
之间的区别fortran 和 c 数组表示是原因吗? 对初始矩阵进行转置可以解决问题吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望你不要期望别人做你的工作。既然你几乎回答了你的问题,我不认为发布它有什么意义。此外,在使用本网站之前花一些时间阅读本网站的常见问题解答部分可能是一件好事。您可能会在那里找到一些有用的信息。
至于问题的答案:
很可能确实是 C 和 Fortran 之间数组表示的差异导致了您的问题。 参阅:
http://en.wikipedia.org/wiki/Row-major_order
请 有关混合 Fortran 和 C 代码的一般信息,这可能会有所帮助:
http://www.yolinux.com /TUTORIALS/LinuxTutorialMishingFortranAndC.html
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