2

任何人都有使用 SymbolicC++ 的经验吗?我正在尝试用这个库解决一些线性问题,但性能似乎不可接受,这是我的测试

#pragma warning(disable: 4800 4801 4101 4390)
#include<iostream>
using namespace std;
#include "Symbolic/symbolicc++.h"

int main() {
    // x==10  y==9  z==7
    Symbolic x("x"), y("y"), z("z");
    Equations rules = (
        x + y + z == 26,
        x - y == 1,
        2*x - y + z == 18
    );

    list<Symbolic> s = (x, y, z);

    list<Equations> result = solve(rules, s); // slow here

    for(auto& x : result) {
        cout << x << endl;
    }
}

在i7 cpu 上求解函数需要 402 毫秒(调试)/67 毫秒(发布),对于像这样的简单问题来说太慢了吗?有谁知道为什么?

谢谢

4

2 回答 2

2

符号计算很慢,如果你想处理公式,就需要它们。

如果您只想求解线性方程组,请考虑使用专门为此创建的工具,例如 Eigen( http://eigen.tuxfamily.org/index.php?title=Main_Page )、BLAS( http://www. netlib.org/blas/)。

另请阅读http://en.wikipedia.org/wiki/Symbolic_computation

于 2013-03-28T10:33:14.553 回答
0

谢谢kassak,刚刚用Eigen完成了这个。

#include <iostream>
#include "Eigen/Dense"
using namespace std;
using namespace Eigen;
int main()
{
    Matrix3f A;
    Vector3f b;
    A <<    1, 1, 1, 
            1,-1, 0, 
            2,-1, 1;
    b <<    26, 1,18;
    cout << "Here is the matrix A:\n" << A << endl;
    cout << "Here is the vector b:\n" << b << endl;
    Vector3f x = A.colPivHouseholderQr().solve(b);
    cout << "The solution is:\n" << x << endl;
}
于 2013-03-29T08:11:08.820 回答