[GiNaC-list] a function without any arguments with GiNaC?

Jorge Cardona jorgeecardona at gmail.com
Mon Jul 27 18:04:48 CEST 2009


Hi,

when you declare a new function on GiNaC you has to declare it with
DECLARE_FUNCTION_xP (where x is the number of parameters), there is no
DECLARE_FUNCTION_0P, and basically, there is no need for it (i think
:), you won't derivate that function, or expand it, so, you don't need
that support to a function of 0 args ).

Why don't you declare it like a normal function?

#include <iostream>
#include <ginac/ginac.h>

using namespace std;
using namespace GiNaC;


ex myfcn(void)
{
    symbol a("a"), b("b"), c("c");

    GiNaC::matrix D(2,2), E(2,2);
    D = a, b,
        0, c;

    E = sin(a), cos(b),
        -sin(c), cos(a);

    return D.mul(E);
}

int main(void)
{
    ex r = myfcn();

    cout << r << endl;
}

/tmp$ g++ -lginac -o test test.cpp
/tmp$ ./test
[[-sin(c)*b+a*sin(a),cos(a)*b+a*cos(b)],[-c*sin(c),c*cos(a)]]

I hope that you find this useful.
Bye.

2009/7/27 Michael Hoffmann <michael.hoffmann at unibw.de>:
> Hallo, how can I make a function without any arguments with GiNaC? I just
> need a function returned a symbolic matrix. It's the same matrix every
> time. How I have to declare  such a function?
>
> minimal example:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <iostream>
> #include <math.h>
> #include <ginac/ginac.h>
> using namespace std;
> using namespace GiNaC;
>
>
> REGISTER_FUNCTION (symbolic_matrix, dummy());
> {
>            symbol a("a"), b("b"), c("c");
>
>            GiNaC::matrix D(2,2), E(2,2);
>
>            D = a, b,
>                  0, c;
>
>            E = sin(a), cos(b),
>                 -sin(c), cos(a);
>
>            GiNaC::ex h = D.mul(E) ;
>
>            return h;
>        }
>
> Thank you very match,
> Michael Hoffmann
>
> P.S. : sorry for my english!
>
> _______________________________________________
> GiNaC-list mailing list
> GiNaC-list at ginac.de
> https://www.cebix.net/mailman/listinfo/ginac-list
>



-- 
Jorge Eduardo Cardona
jorgeecardona at gmail.com
jorgeecardona.blogspot.com
------------------------------------------------
Linux registered user  #391186
Registered machine    #291871
------------------------------------------------


More information about the GiNaC-list mailing list