[GiNaC-list] Referencing array of symbols?
Sheplyakov Alexei
varg at theor.jinr.ru
Wed Sep 7 10:54:12 CEST 2005
On Wed, Sep 07, 2005 at 05:56:01PM +1000, John Pye wrote:
> I'm struggling to understand how to correctly use the 'idx'
> functionality in GiNaC.
See http://www.ginac.de/FAQ.html#matrix_indexed for a (short) explanation.
> 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
> numerical solver.
Probably, I'm just missing something important, but I don't understand
why you need to do _symbolic_ manipulations in this problem.
> 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.
Why don't you use an associative array, e.g. std::map<sybol, ex, ex_is_less>,
or just GiNaC::exmap?
> Also, I'd like to know your thoughts on how efficient this sort of
> approach might be as the number of equations / symbols grows.
I don't think your approach will be efficient.
> Am I right in thinking I shuold be using the 'idx' class?
NO!
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20050907/00ab175d/attachment.pgp
More information about the GiNaC-list
mailing list