]> www.ginac.de Git - ginac.git/blob - doc/examples/derivative.cpp
Replaced dummy reference by correct reference.
[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 #ifdef IN_GINAC
9 #include "ginac.h"
10 #else
11 #include <ginac/ginac.h>
12 #endif
13 using namespace std;
14 using namespace GiNaC;
15
16 int main()
17 {
18         cout << "Enter an expression containing 'x': " << flush;
19         parser reader;
20
21         try {
22                 ex e = reader(cin);
23                 symtab table = reader.get_syms();
24
25                 symbol x = table.find("x") != table.end() ? 
26                            ex_to<symbol>(table["x"]) : symbol("x");
27
28                 cout << "The derivative of " << e << " with respect to x is ";
29                 cout << e.diff(x) << "." << endl;
30         } catch (exception &p) {
31                 cerr << p.what() << endl;
32         }
33 }
34