[GiNaC-list] Symbolic computation and derivatives
Antoine Begault
antoine.begault at inrialpes.fr
Fri May 11 12:11:19 CEST 2007
Hello,
I am currently trying the functionalities of GiNaC in order to translate
some Maple code to C++ code, for a Matrix-using application. But I'm
facing some difficulties for which some help could be very useful.
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).
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?
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.
How we do this in Maple is substitute symbols q[i] by functions q[i](t),
differentiate with respect to t, then substitute back q[i](t) with q
[i] and
diff(q[i](t),t) with qdot[i] with the following code:
> R=matrix(3,3);//+ initialization
> map(x->subs({seq(q[i](t)=q[i], i=1..NDDL),
> seq(diff(q[i](t), t)=qdot[i], i=1..NDDL)},
> diff(subs({seq(q[i]=q[i](t), i=1..NDDL)}, x), t)), P)):
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?
Many thanks for your time and help,
A. Begault.
--
View this message in context: http://www.nabble.com/Symbolic-computation-and-derivatives-tf3726576.html#a10429229
Sent from the Ginac - General mailing list archive at Nabble.com.
More information about the GiNaC-list
mailing list