C ++ MTL matrix line exchange example (finishing by Robinkin from Devonit)

xiaoxiao2021-03-06  44

#include "mtl / matrix.h"

#include "mtl / mtl.h"

#include "mtl / utils.h"

/ *

Swaps the first row with the row what has the largest element in

Column 1. this is the Kind of Operation One Would Do Inside A

Gaussian Elimintation Algorithm.

Sample Output

3x3

[

[1, 1.5, 4.5],

[3, 2.5, 9.5],

[2, 3.5, 5.5]

]

3x3

[

[3, 2.5, 9.5],

[1, 1.5, 4.5],

[2, 3.5, 5.5]

]

* /

Using namespace MTL;

Using namespace std;

int

Main ()

{

// begin

TypedEf Matrix

Rectangle <>,

Dense ,

COLUMN_MAJOR> :: Type Matrix;

Const matrix :: size_type n = 3;

Matrix :: size_type large;

Double Da [] = {1, 3, 2, 1.5, 2.5, 3.5, 4.5, 9.5, 5.5};

Matrix A (DA, N, N);

// end

Print_all_matrix (a);

// begin

// Find The Largest Element in The First Column.

Large = max_index (a [0]); // The largest element in the first column is located

// end

Cout << "x" << Endl;

// begin

// swap the first row with the row contact the largest

// Element in the first column.

SWAP (Rows (a) [0], ROWS (A) [Large]); // Exchange the first line and target line

// end

Print_all_matrix (a);

Return 0;

}

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

New Post(0)