]> www.ginac.de Git - ginac.git/blob - doc/examples/derivative.cpp
Fixed include of stdint.h (parser.cpp needs the header as well).
[ginac.git] / doc / examples / derivative.cpp
1 // Input expression containing variable 'x' and compute its derivative
2 // with respect to 'x'.
3 // Example from the tutorial (chapter Input/Output, section `Expression
4 // input').
5 #include <iostream>
6 #include <string>
7 #include <stdexcept>
8 #include <ginac/ginac.h>
9 using namespace std;
10 using namespace GiNaC;
11
12 int main()
13 {
14         cout << "Enter an expression containing 'x': " << flush;
15         parser reader;
16
17         try {
18                 ex e = reader(cin);
19                 symtab table = reader.get_syms();
20
21                 symbol x = table.find("x") != table.end() ? 
22                            ex_to<symbol>(table["x"]) : symbol("x");
23
24                 cout << "The derivative of " << e << " with respect to x is ";
25                 cout << e.diff(x) << "." << endl;
26         } catch (exception &p) {
27                 cerr << p.what() << endl;
28         }
29 }
30