c++ - How do I evaluate a Symbolic variable in SymbolicC++? -


i have been trying out couple computer algebra libraries c++ use vector calculus course taking. having trouble nonlinear equations in ginac , in symbolicc++ worked.

here simple example, problem can't figure out how evaluate number , maybe cast 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 = 1;     for( auto iter1 = sols.begin(); iter1 != sols.end(); iter1++)     {         x_sol = x.subst((*(*iter1).begin()));         y_sol = y.subst((*(--(*iter1).end())));         cout << "p" << << " = {" << x_sol << ", " << y_sol << "};" << endl;         i++;     }     return 0; } 

with output can copy , past ginsh , evaluates fine, stays in expanded form in symbolicc++.

the exact ouput getting 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 evaluate expressions these , cast them doubles?

i realize answer year old question. there's no way directly cast string number. need calculate floating-point value you're interested - same way on calculator. https://code.google.com/p/exprtk/ link easy use library accomplish you're looking for. have symbolic object string class using string stream


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -