Hi, I try to use an undefined function, such as f(x), instead of f(x)=3*x+... I know that the function depends on variable x, but not in what form. With SymbolicC++, if I define Symbolic x("x"), f[x] and g[x], the operation diff( f+g ,x ) returns diff(f,x)+diff(g,x). (the differentiation rule of sum operator) It is possible to make this with GiNaC? Thanks
Hello, On Thu, Sep 9, 2010 at 4:48 PM, Jose Antonio Garcia Peiro <jgpeiro@gmail.com> wrote:
I try to use an undefined function, such as f(x), instead of f(x)=3*x+... I know that the function depends on variable x, but not in what form. With SymbolicC++, if I define Symbolic x("x"), f[x] and g[x], the operation diff( f+g ,x ) returns diff(f,x)+diff(g,x). (the differentiation rule of sum operator) It is possible to make this with GiNaC?
You might want to try this: #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; DECLARE_FUNCTION_1P(f) DECLARE_FUNCTION_1P(g) REGISTER_FUNCTION(f, dummy()) REGISTER_FUNCTION(g, dummy()) int main(int argc, char** argv) { symbol x("x"); ex e = f(x) + g(x); ex e_prime = e.diff(x); cout << "d/dx(" << e << ") = " << e_prime << endl; return 0; } Best regards, Alexei
participants (2)
-
Alexei Sheplyakov
-
Jose Antonio Garcia Peiro