2010-11-30 31 views
1

是否有可能使用Accelerate/LAPACK解決一個非方形under/over約束矩陣?如下面的兩個矩陣。如果任何變量受到約束,它們應該等於0而不是無限。是否有可能使用Accelerate/LAPACK解決一個非方形under/over約束矩陣?

所以在受到約束的情況下:A,D & E會等於0,而B,C & F等於-1。

在約束情況下,所有變量都等於-1。

欠約束:

____      ____ 
| (A) (B) (C) (D) (E) (F)  | 
| -1 0 0 1 0 0 | 0 | 
| 1 0 0 0 -1 0 | 0 | 
| 0 -1 1 0 0 0 | 0 | 
| 0 1 0 0 0 -1 | 0 | 
| 0 1 0 0 0 0 | -1 | 
|____      ____| 

過約束:

____      ____ 
|        | 
| -1 0 0 1 0 0 | 0 | 
| 1 0 0 0 -1 0 | 0 | 
| 0 -1 1 0 0 0 | 0 | 
| 0 1 0 0 0 -1 | 0 | 
| 0 1 0 0 0 0 | -1 | 
| 0 0 1 -1 0 0 | 0 | 
| 1 -1 0 0 0 0 | 0 | 
|____      ____| 

回答

1

是的!

void SolveUnderdeterminedSystem() { 

    __CLPK_integer m = 5; 
    __CLPK_integer n = 6; 
    __CLPK_integer nrhs = 1; 
    double A[30] = { 
     -1.0, 1.0, 0.0, 0.0, 0.0, 
     0.0, 0.0, -1.0, 1.0, 1.0, 
     0.0, 0.0, 1.0, 0.0, 0.0, 
     1.0, 0.0, 0.0, 0.0, 0.0, 
     0.0, -1.0, 0.0, 0.0, 0.0, 
     0.0, 0.0, 0.0, -1.0, 0.0 
    }; 
    __CLPK_integer lda = 5; 
    double x[6] = { 0.0, 0.0, 0.0, 0.0, -1.0, 0.0 }; 
    __CLPK_integer ldb = 6; 
    /* Need to allocate at least 2*min(m,n) workspace. */ 
    double work[12]; 
    __CLPK_integer workSize = 12; 
    __CLPK_integer info; 

    dgels_("N", &m, &n, &nrhs, A, &lda, x, &ldb, work, &workSize, &info); 

    if (info) 
     printf("Could not solve system; dgels exited with error %d\n", info); 
    else 
     printf("Solution is [%f, %f, %f, %f, %f, %f]\n", 
       x[0], x[1], x[2], x[3], x[4], x[5]); 
} 

相同的程序也將解決在最小二乘意義超定系統(其結果將是殘留|| Ax的極小 - B ||)。

注意,dgels_假定矩陣具有滿秩(即rank(A)= min(m,n))。如果情況並非如此,則需要使用不同的例程(dgelsd_),該程序使用SVD分解而不是QR。

你似乎在問LAPACK的問題。這是非常值得您花時間閱讀the documentation

+0

試圖找到我從大學的差異書籍的審查,但沒有,所以我想記住如何做到這一切,因爲我去。抱歉。同樣thx的答案 – John 2010-11-30 22:54:34

相關問題