Question regarding symbolic differentiation
Hello, i have a question regarding symbolic differentiation with GiNAC. Here is what i am trying to do: I have to variables a(t) and b(t), both are dependent from time (t). Suppose, this two variables are multiplied liked this: a(t) * b(t) Is it possible to derive this expression (a(t)*b(t)) according time with ginac. The only function i found in the manual is usefull for partial derivation, which does not help me here. Here is some example code: symbol a("a"), b("b"); // <-- how to tell ginac that variable a and b is dependant from variable t expression f = a*b; std::cout << f.diff(t,1) << std::endl; Many thanks in advance and best regards Martin Ettl
Hello, To do the symbolic differentiation, I created a new class, that store the dependencies with respect to a symbol (or many) and the degree of differentiation. Then I can differentiate the symbol (add 1 to the degree). and at the end I can make the substitution and the real differentiation. I'm not sure that is the correct approach, but it works for me. Felipe. Le 22 juil. 12 à 19:29, Martin Ettl a écrit :
Hello,
i have a question regarding symbolic differentiation with GiNAC.
Here is what i am trying to do:
I have to variables a(t) and b(t), both are dependent from time (t). Suppose, this two variables are multiplied liked this:
a(t) * b(t)
Is it possible to derive this expression (a(t)*b(t)) according time with ginac.
The only function i found in the manual is usefull for partial derivation, which does not help me here.
Here is some example code:
symbol a("a"), b("b"); // <-- how to tell ginac that variable a and b is dependant from variable t expression f = a*b; std::cout << f.diff(t,1) << std::endl;
Many thanks in advance and best regards
Martin Ettl
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
Thank you very much ( Felipe and Jens), both ways are good for me. Best regards and keep up the great work on GiNaC!! Martin Ettl 2012/7/22 Felipe Bordeu Weldt <felipe.bordeu@ec-nantes.fr>
Hello,
To do the symbolic differentiation, I created a new class, that store the dependencies with respect to a symbol (or many) and the degree of differentiation.
Then I can differentiate the symbol (add 1 to the degree). and at the end I can make the substitution and the real differentiation.
I'm not sure that is the correct approach, but it works for me.
Felipe.
Le 22 juil. 12 à 19:29, Martin Ettl a écrit :
Hello,
i have a question regarding symbolic differentiation with GiNAC.
Here is what i am trying to do:
I have to variables a(t) and b(t), both are dependent from time (t). Suppose, this two variables are multiplied liked this:
a(t) * b(t)
Is it possible to derive this expression (a(t)*b(t)) according time with ginac.
The only function i found in the manual is usefull for partial derivation, which does not help me here.
Here is some example code:
symbol a("a"), b("b"); // <-- how to tell ginac that variable a and b is dependant from variable t expression f = a*b; std::cout << f.diff(t,1) << std::endl;
Many thanks in advance and best regards
Martin Ettl
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
Hi, On 22.07.2012 19:29, Martin Ettl wrote:
I have to variables a(t) and b(t), both are dependent from time (t). Suppose, this two variables are multiplied liked this:
a(t) * b(t)
Is it possible to derive this expression (a(t)*b(t)) according time with ginac.
yes, and like your notation already suggests, you need to define a and b as functions of t. A simple code example would be: #include <ginac/ginac.h> using namespace GiNaC; #include <iostream> using namespace std; DECLARE_FUNCTION_1P(a) DECLARE_FUNCTION_1P(b) REGISTER_FUNCTION(a, dummy()) REGISTER_FUNCTION(b, dummy()) int main() { symbol t("t"); ex expr = a(t) * b(t); cout << expr << endl; cout << expr.diff(t,1) << endl; return 0; } But you will get fderivative objects in the result (printed as something like D[0], because with dummy() in the function definition macro you have not told GiNaC what the partial derivative of a or b with respect to t is supposed to be. You can look in the tutorial in section 6.2.2 for a more elaborate example. Regards, Jens
participants (3)
-
Felipe Bordeu Weldt
-
Jens Vollinga
-
Martin Ettl