任何方式来实现Excel LINEST函数使用boost库?

boost :: math是否有任何函数可以用来帮助实现一个类似于MS Excel LINEST函数的函数?

我parsing了Boost文档(不是在boost :: math中,它看起来更像boost :: ublas)。 就目前而言,我找不到一个足够简单的例子,对于一个非math家来说不会过分。

从我看到的,我宁愿build议使用犰狳 ,因为它的使用似乎相当简单。

我已经在下面转载了一个从犰狳源代码存档取得的简单代码示例:

int main(int argc, char** argv) { // points to which we will fit the line mat data = "1 6; 2 5; 3 7; 4 10"; // Transform the problem into an Armadillo use-case (Ax = b problem) vec b(data.n_rows); mat C(data.n_rows, 2); for(u32 i=0; i<data.n_rows; ++i) { b(i) = data(i,1); C(i,0) = 1; C(i,1) = data(i,0); } // Compute least-squares solution, should be "3.5; 1.4" vec solution = solve(C,b); cout << "solution:" << endl << solution << endl; return 0; } 
Interesting Posts