MTL LU Decomposition Example

xiaoxiao2021-03-06  40

/ / - * - C - * ------------------------------------------------------------------------------------------------------------------------------------ ----------------------- //// A Simple Lu Factorization Algorithm Written Using MTL // The Example Matrix Is The Same As The Geth EXAMPLE, WHICH / / Is the lapack version of l factorization./////--------------------------------------- ------------------------------------

#include "mtl / lu.h" #include "mtl / matrix.h" #include "mtl / dense1d.h" #include "mtl / utils.h"

/ * Sample Output: 3X3 [[1, 2, 2], [2, 1, 2], [2, 2, 1]] 3X3 [[2, 1, 2], [0.5, 1.5, 1], [ 1, 0.666667, -1.66667]] [2, 2, 3,]

That is, pivot = [2, 0, 0,] [0, 2, 0,] [0, 0, 3,]

L = [2 * 2, 0], [0.5, 1.5 * 2, 0], [1, 0.666667, -1.66667 * 3]

U = [1, 1, 2], [0, 1, 1], [0, 0.666667, 1]

* /

INTMAIN () {Using Namespace MTL; // Begin Typedef Matrix , Dense , Column_major> :: Type Matrix

Const matrix :: size_type n = 3; double da [] = {1, 2, 2, 2, 1, 2, 2, 2, 1};

Matrix A (DA, N, N); DENSE1D pivots (n, 0); // end print_all_matrix (a); // begin lu_factor (a, pivots); // end print_all_matrix (a);

Print_vector (pivots);

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-50939.html

New Post(0)