CLAPACK for Windows

來源:互聯網
上載者:User

下載和教程(光看這兩個大概就會安裝和是使用了)

  clapack : http://icl.cs.utk.edu/lapack-for-windows/clapack/index.html

  lapack : http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries_mingw

  (把下載的檔案放在VS的合適目錄下即可)

----

  

CLAPACK是LAPACK的C語言介面。LAPACK的全稱是Linear Algebra PACKage,是非常著名的線性代數庫。LAPACK是用Fortran寫的,為了方便C/C++程式的使用,就有了LAPACK的C介面庫CLAPACK。LAPACK的首頁是http://www.netlib.org/lapack/,CLAPACK的首頁在http://www.netlib.org/clapack/。

CLAPACK有Linux和Window版。安裝CLAPACK-Windows首先從其首頁上下載CLAPACK-Windows包,解壓,然後用VC(我用的是VS2005)開啟clapack.dsw,編繹既可。CLAPACK下的 clapack.h 是所需要的標頭檔,除此之外還需要的一個標頭檔是F2CLIBS/f2c.h。

 

現在通過使用CLAPACK中的一個函數sgesv_解線性方程組來學習一下使用的方法。

 

包括此函數在內的所有函數可以在CLAPACK/SRC下找到原始碼,並在代碼中有函數參數的說明資訊。sgesv_的代碼檔案就是sgesv.c。 

int sgesv_(integer *n, integer *nrhs, real *a, integer *lda, integer *ipiv, real *b, integer *ldb, integer *info)

sgesv_的功能是使用LU分解法解線性方程組AX=B,其中A是一個n*n的方陣。

integer *n, 方程的個數,也既A的行數和列數

integer *nrhs, B的列數

real *a, 儲存矩陣A資料的一維數組,在fortran中,數組是列主序儲存,在此a中的二維資料也必須是列主序

integer *lda, 等於n

integer *ipiv, 一個輸出資料數組,數組大小是n,具體什麼功能不太明白,但是似乎不影響最後結果,誰明白請告訴我

real *b,儲存矩陣B資料的一維數組,在fortran中,數組是列主序儲存,在此b中的二維資料也必須是列主序

integer *ldb, 等於n

integer *info,輸出參數,如果返回此參數為0,表示函數正常退出,否則表示出錯

 

以下是代碼:

 1 // mytest.cpp : Defines the entry point for the console application. 2 // 3  4 #include "stdafx.h" 5  6 #include <iostream> 7  8 using namespace std; 9 10 #include <F2CLIBS/f2c.h>11 12 //因為程式是C++,而CLAPACK是C語言寫的,所以在此處用extern關鍵字13 extern "C"14 {15 #include <clapack.h> 16 }17 18 19 int _tmain(int argc, _TCHAR* argv[])20 {21 integer M=3 ;22 integer N=1;23 real a[9]={4,3,11,2,-1,0,-1,2,3};24 real b[3]={2,10,8};25 integer lda;26 integer ldb;27 integer INFO;28 29 lda=M;30 ldb=M; 31 integer *ipiv;32 ipiv = (integer *)new integer[M];33 34 sgesv_(&M, &N, a, &lda,ipiv, b, &ldb, &INFO);35 36 if(INFO==0)37 {38    for(int i=0; i<M; i++)39    {      40     cout<<b[i]<<endl;41    } 42 }43 else44 {45    cout<<"Failed."<<endl;46 }  47 48 return 0;49 }50 51  

編譯連結時要將clapack.lib加進連結庫裡。

 

[轉]http://hi.baidu.com/xuyungui/blog/item/c43ef9026e8cff713912bbd3.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.