C++ MTL 矩阵 行交换 示例 (整理 by RobinKin from DevonIT)
2005-02-25 12:36
337 查看
#include "mtl/matrix.h"
#include "mtl/mtl.h"
#include "mtl/utils.h"
/*
Swaps the first row with the row that 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< double,
rectangle<>,
dense<external>,
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]); //第一列中最大元素所在行号
//end
cout << "x" << endl;
//begin
// Swap the first row with the row containing the largest
// element in the first column.
swap( rows(A)[0] , rows(A)[large]);//交换第一行和目标行
//end
print_all_matrix(A);
return 0;
}
#include "mtl/mtl.h"
#include "mtl/utils.h"
/*
Swaps the first row with the row that 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< double,
rectangle<>,
dense<external>,
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]); //第一列中最大元素所在行号
//end
cout << "x" << endl;
//begin
// Swap the first row with the row containing the largest
// element in the first column.
swap( rows(A)[0] , rows(A)[large]);//交换第一行和目标行
//end
print_all_matrix(A);
return 0;
}
相关文章推荐
- C++ 的 MTL 库 示例(整理 by RobinKin from DevonIT)
- boost 检查(测试)库 示例 (RobinKin 整理)
- 整理android逆向工程师技能表 by非虫from看雪
- 排序算法整理(C++):插入排序、交换排序、选择排序、归并排序
- How to use an Outlook Object Model from Visual C++ by using a #import statement
- C++新风格的强制类型转换(by Morphy, from csdn community)
- GitHub 通告:整理了一个 C 和 C++ 开源库的清单(含示例代码)
- Calling Fortran functions from C++ by means of shared libraries
- python调用c/c++方式示例(修改整理)
- Leetcode_c++: Remove Duplicates from Sorted Array II (080)
- oracle exp/imp示例及使用问题整理
- C++ 数据库连接代码示例
- c/c++概念整理1
- 最新【独家沙龙内容整理】机器女友?—百度微软讯飞等顶级专家谈人机对话黑科技及未来 ——by中科院孢子创客空间
- C++中引用传递与指针传递区别(进一步整理)
- cmake使用示例与整理总结
- c++第二周任务三#(3-2)整理规范的文本
- C++STL之整理算法
- C++ 11: function & bind 使用示例
- C++ 命名空间整理