[GiNaC-list] Symbolic computation and derivatives
Chris.Dams at mi.infn.it
Chris.Dams at mi.infn.it
Wed May 16 17:44:44 CEST 2007
Dear Antoine,
> First, I need to represent a symbolic vector and then functions of this
> vector. So far, I've been using 'n' distincts symbols for a vector of
> size 'n', which is certainly not the best way, especially for what I
> need
> to do afterwards (c.f the example below).
If your functions are or can be written in a co-ordinate independent way.
I.e., as a tensor expression, you can use indexed objects for the
components of the vector. If not, then creating n different symbols seems
to be the only way.
> Then, I need to compute the derivative of a function with respect to the
> previous vector, i.e. a gradient or a Jacobian matrix. With the "n
> distinct
> symbols" solution, I would do that by derivating n times, but it
> would be
> much more efficient if the whole gradient computation could be done in
> only one step: do you see any better way to do so within GiNaC?
I do not really see an easier way, I'm afraid. In the case that your
function can be written as a tensor expression, it would be nice if GiNaC
was able to differentiate with respect to a symbol carrying indices.
Unfortunately it can only differentiate with respect to symbols at the
moment.
> Finally, it happens that this vector is itself a function of time and
> I need
> sometimes to compute derivatives of functions of this vector with
> respect
> to time (in a more efficient way than just computing the aforementioned
> gradient or Jacobian and remultiplyling it by the time-derivative of the
> vector). I need therefore to express that a symbol (the members of the
> vector) is in fact a function of another symbol, with respect to
> which I can
> compute derivatives.
I think you would need to use the same way as you used with Maple.
> Doing something similar with GiNaC requires that we deal with user
> defined functions, but the "function" objects don't look like they
> are really
> made on this purpose: am I understanding correctly? We would define 'n'
> functions q[i](t) with derivatives defined as 'n' other functions qdot
> [i](t),
> something like that, but isn't there any simpler and more effective way?
The functions q[i] would not need to know their derivative (you are
talking about functions as in the class GiNaC::function, I think). In that
case they would simply return something that looks like D[0](q[i])(t). You
could also consider the idea of making i another parameter of your
function. That way you would have q(i, t), which could easily be more
convenient to create.
Good luck,
Chris
More information about the GiNaC-list
mailing list