基於 MATRIX 類的矩陣分解和方程組求解

2021-06-01 05:31:55 字數 2183 閱讀 1452

前一篇日誌主要是乙份 matrix 的類說明書,經過擴充套件之後現在可以可以對矩陣進行幾種常見的分解運算,可以用來求解線性方程組。

例程1:

#include "matrix.h"

using namespace std;

int main(int argc,char* argv)

; matrix a(4,4,a);

matrix p(4,4);//elementary transformal matrix

matrix b=ludecomposition(a);

matrix c=column_pivotlu(a,p);

matrix d=cholesky(a);//cholesky decomposition

matrix l,u;

cout<<"lu decomposition:"<

結果如下:

lu decomposition:

16.0000  4.0000  8.0000  4.0000

0.0000  9.0000  6.0000  3.0000

0.0000  0.0000  4.0000  6.0000

0.0000  0.0000  0.0000  1.0000

1.0000  0.0000  0.0000  0.0000

0.2500  1.0000  0.0000  0.0000

0.5000  0.6667  1.0000  0.0000

0.2500  0.3333  1.5000  1.0000

lu decomposition under coloumn-pivot rule:

16.0000  4.0000  8.0000  4.0000

0.0000  9.0000  6.0000  3.0000

0.0000  0.0000  6.0000 10.0000

0.0000  0.0000  0.0000 -0.6667

1.0000  0.0000  0.0000  0.0000

0.2500  1.0000  0.0000  0.0000

0.2500  0.3333  1.0000  0.0000

0.5000  0.6667  0.6667  1.0000

cholesky decomposition:

4.0000  1.0000  2.0000  1.0000

0.0000  3.0000  2.0000  1.0000

0.0000  0.0000  2.0000  3.0000

0.0000  0.0000  0.0000  1.0000

4.0000  0.0000  0.0000  0.0000

1.0000  3.0000  0.0000  0.0000

2.0000  2.0000  2.0000  0.0000

1.0000  1.0000  3.0000  1.0000

0.75

0.42

-1.17

7.33

2.79

5.42

-11.58

7.33

process returned 0 (0x0)   execution time : 0.214 s

press any key to continue.

例程2:

#include "matrix.h"

using namespace std;

int main(int argc,char* argv)

; double barray=;

matrix a(3,3,aarray);

matrix l,u,y,x,b(3,1,barray);

cout<<"a:"<

結果如下:

a:2.00 -1.00 3.00

4.00 2.00 5.00

2.00 1.00 2.00

b:1.00

4.00

5.00

the answer is:

9.00

-1.00

-6.00

process returned 0 (0x0)   execution time : 0.188 s

press any key to continue.

新的 matrix 類已經上傳到資源,免費開源,歡迎修改完善。

基於矩陣分解的推薦系統

推薦系統產生推薦列表的方式通常有兩種 協同過濾以及基於內容推薦,或者基於個性化推薦。協同過濾方法根據使用者歷史行為 例如其購買的 選擇的 評價過的物品等 結合其他使用者的相似決策建立模型。這種模型可用於 使用者對哪些物品可能感興趣 或使用者對物品的感興趣程度 基於內容推薦利用一些列有關物品的離散特徵...

推薦系統例項 基於矩陣分解

使用matlab嘗試了隨機梯度下降的矩陣分解方法,實現了乙個比較簡單的推薦系統的原理。常用推薦系統的方法有協同過濾,基於物品內容過濾等等。這次是用的矩陣分解模型屬於協同過濾的一種方法,大致原理是通過一定數量的因子來描述各個使用者的喜好和各個物品的屬性。通過隨機梯度下降法分解後得到兩個矩陣,乙個是使用...

基於C 的矩陣類

這個矩陣類雖然小,但有專門的官網,很適合用小型專案。特別是,它完全過載了所有矩陣的運算子,矩陣的加減乘法,轉置,求逆等等,都實現得非常好。例如下邊這個官網的例項 問題 設定乙個二維陣列 double a new double 4,4 double c new double 4,1 用二維陣列構建乙個...