2

Does anyone use the GINAC? Can you tell me how to init an ex object with a string, or convert a string to ex?

jogojapan
  • 68,383
  • 11
  • 101
  • 131
EastStar
  • 23
  • 3
  • 1
    Doesn't the constructor documented here do it: http://www.ginac.de/reference/classGiNaC_1_1ex.html#ace68037326c1a2b8c93a56716599ec7a – jogojapan Nov 30 '12 at 01:59
  • I have tried this method,but it can't work!And what is the meaning of the second parameter ex? – EastStar Nov 30 '12 at 04:55

1 Answers1

1

If you have a string that contains the correct expression syntax, you can use the constructor documented here to turn it into an ex object.

You need to supply a second argument, which must be a list (in the sense of a lst object) of symbols. This list must contain the user-defined symbols you use in the expression. If you don't use any user-defined symbols, use an empty list.

Example with no user-defined symbols:

  using namespace std;
  using namespace GiNaC;

  ex myex("2+3",lst());      // Output will be '5'

  cout myex << endl;

Example using two user-defined symbols:

  using namespace std;
  using namespace GiNaC;

  symbol x("x");
  symbol y("y");
  ex myex("x^3+y",lst(x,y));

  cout << myex + y << endl;     // Output will be '2*y+x^3'

In the last example, you can see that the character 'y' in the input string "x^3+y" was indeed interpreted as the symbol y: myex + y is simplified to "2*y+x^3".

jogojapan
  • 68,383
  • 11
  • 101
  • 131
  • Sorry,I think you have not understood what I mean.I show an example. – EastStar Nov 30 '12 at 07:07
  • string s("Hello"); ex e; How to pass the value of string s to ex e? – EastStar Nov 30 '12 at 07:08
  • e can implement many mathematical operations,such as add(), expand(), factor and so on. – EastStar Nov 30 '12 at 07:24
  • 1
    I have solved the problem.Just like what you said.I can use e(s,lst()) to implement. – EastStar Nov 30 '12 at 07:26
  • Just like this,I want to read a string and show the result on the mai screen. - (NSString *)combine:(NSString *)input{ symbol x("x"); symbol y("y"); string str(""); ex b; str = [input cStringUsingEncoding:NSUTF8StringEncoding]; ex ec(str,lst(x,y)); cout<<"ec is"< – EastStar Nov 30 '12 at 07:42
  • on the main screen,not the mai screen – EastStar Nov 30 '12 at 07:43