How to evaluate a symbolic variable in SymbolicC ++?

I tested a couple of computer algebra libraries for C ++ for use with the vector calculus course that I am taking. I'm having problems with non-linear equations in GiNaC, and in SymbolicC ++ it really worked.

Here is a simple example, but the problem is that I cannot figure out how to evaluate a number and possibly translate it into double or float:

#include <iostream>
#include "symbolicc++.h"

using namespace std;
int main(void)
{
    Symbolic x("x"), y("y");

    Equation e1 = (x^2) + (y^2) == 13;
    Equation e2 = (x^2) - y == 7;

    Equations eqs = {e1, e2};
    list<Symbolic> symbs = {x, y};
    list<Equations> sols = solve(eqs, symbs);

    Symbolic x_sol, y_sol;
    int i = 1;
    for( auto iter1 = sols.begin(); iter1 != sols.end(); iter1++)
    {
        x_sol = x.subst((*(*iter1).begin()));
        y_sol = y.subst((*(--(*iter1).end())));
        cout << "p" << i << " = {" << x_sol << ", " << y_sol << "};" << endl;
        i++;
    }
    return 0;
}

With this output, I can copy and skip it to ginsh, and it is rated just fine, but it remains in extended form in SymbolicC ++.

The exact output I get is as follows:

p1 = {1/2*(-2*(25)^(1/2)+26)^(1/2), -1/2*(25)^(1/2)-1/2};
p2 = {1/2*(2*(25)^(1/2)+26)^(1/2), 1/2*(25)^(1/2)-1/2};
p3 = {-1/2*(-2*(25)^(1/2)+26)^(1/2), -1/2*(25)^(1/2)-1/2};
p4 = {-1/2*(2*(25)^(1/2)+26)^(1/2), 1/2*(25)^(1/2)-1/2};

How can I evaluate expressions like these and assign them to doubles?

+4
2

, . . - , . https://code.google.com/p/exprtk/ - , . Symbolic ,

+6

Try:

cout << "p" << i << " = {" << double(x_sol) << ", " << double(y_sol) << "};" << endl;
0

All Articles