如何设计 :: 矩阵的线性代数例程

How to design :: Linear Algebra Routines for a matrix

在 C++ 中,出于教育目的,我正在构建一个线性代数包。 我的问题是如何为用户设计一个好的界面。

我有一个矩阵 class 可以创建为

matrix<int> A (3,3)

这 class 处理存储在矩阵中的数据,如何遍历它们,获取特定元素,打印矩阵等...

我有另一个 class 线性代数,它对矩阵进行数学计算。所以它会像这样工作

LA<int> B ;

// I have a method in LA , which gives the determinant. 

matrix<int> C = B.determinant(A);

// Just doesn't look good to me, I want to be able to do this 

matrix<int> C = determinant(A); // This seems more natural 

// Is there any way to eliminate the need to create an LA object ?

一种方法是在 A 中定义行列式并调用 A.determinant()。但这并没有给我模块化。

那我该怎么做呢?

另外

您可以拥有实用程序命名空间:

namespace UTILITY {
// define determinant here
}

然后在本地你可以使用:

typedef UTILITY::determinant determinant; 

然后使用:

determinant(A);