[GiNaC-list] Referencing array of symbols?

John Pye john.pye at student.unsw.edu.au
Wed Sep 7 09:56:01 CEST 2005

Hi there

I'm struggling to understand how to correctly use the 'idx'
functionality in GiNaC. If anyway would be able to offer some
suggestions or relevant examples, I'd be very appreciative.

My application is for something like a simple one-dimensional pipe flow
calculation. For example, I would like to evaluate the pressures in the
flow alow a pipe. I will set up some expressions relating the values of
my pressures at different nodes in my pipe, then I will substitute
values for those pressures and then evaluate residuals from my expressions.

So I am hoping to write something like

sym p[100] = sym[]("p");
sym mdot[100] = sym[]("mdot");
sym rho("rho");

lst f;
for(int i=1; i<100; ++i){
    f.append( p[i] - p[i-1] - 0.5 * rho * pow( mdot[i-1] / (rho * A) , 2) );

for(int i=1; i<100; ++i){
    f.subs(p[i] == 1.5454223494);

cerr << f << endl;

In this way, I will have an array of symbols and a lst of expressions. I
can then use those to generate equations which can be exported to s
numerical solver.

Perhaps the best way to do this is to create standard C-style array of
symbols? I am hoping there's a more elegant way. Also, I'd like to know
your thoughts on how efficient this sort of approach might be as the
number of equations / symbols grows. Am I right in thinking I shuold be
using the 'idx' class?



John Pye
School of Mechanical and Manufacturing Engineering
The University of New South Wales
Sydney  NSW 2052  Australia
t +61 2 9385 5127
f +61 2 9663 1222

More information about the GiNaC-list mailing list