Hello Dr. Kisil, The question from C. Trophime is not about evaluating the function but to define it. Feel++ <http://www.feelpp.org> is a Finite Element library that main goal is to solve the variational problem a(u,v)=f(v) that arises from a lot of physical problems. We use GiNaC to dynamically define the right hand side of our problem, or our boundaries conditions and whatever can be expressed with it. The question - I guess - can be explained like that : I would like to define - f(x) = 2*x if x>0 - f(x) = 3*x if x<=0. Thus, basically, I would like to write ex MyEx = (x<=0)?3*x:2*x To my best knowledge, boolean expression are not handled in GiNaC, isn’t it ? all the best, Vincent H. -- Docteur Ingénieur de recherche CeMoSiS <http://www.cemosis.fr> - vincent.huber@cemosis.fr Tel: +33 (0)3 68 8*5 02 06* IRMA - 7, rue René Descartes 67 000 Strasbourg
Dear Vincent, You are right that GiNaC expression do not admit boolean terms directly. However with your example you can proceed as follow (I do understand that your actual target is much more complicated): 1. Use the step function from GiNaC: f=2*x*step(x)+3*x*step(-x). [but for x=0 you need take care as step(0)=.5] Of course, if you have a hundred points where the function changes the expression, this becomes much more complicated 2. Define your own function of three variables S(a,b,x) such that S(a,b,x)=1 for a<x<b and zero otherwise. GiNaC tutorial contains a demonstration how make a user-defined function. Then, any piece-wise function F will be a sum of terms f_i(x)*S(a_i,_b_i,x) where f_i is the expression for F on [a_i,b_i] (assuming disjoint partition. 3. Finally, you may derive your own class from GiNaC::basic to hold your piece-wise function (again, GiNaC tutorial gives an example). As I see it shall have two lists: one with points of the partition, another with the respective expression. Then you add your custom methods to operate this class. The approaches are given in the order of increasing complexity, but the efficiently shall grow in the same direction. Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
On Wed, 22 Apr 2015 16:47:13 +0200, Vincent Huber <vincent.huber@cemosis.fr> said:
VH> Hello Dr. Kisil, VH> The question from C. Trophime is not about evaluating the VH> function but to define it. Feel++ <http://www.feelpp.org> is a VH> Finite Element library that main goal is to solve the VH> variational problem a(u,v)=f(v) that arises from a lot of VH> physical problems. VH> We use GiNaC to dynamically define the right hand side of our VH> problem, or our boundaries conditions and whatever can be VH> expressed with it. VH> The question - I guess - can be explained like that : I would VH> like to define VH> - VH> f(x) = 2*x if x>0 - VH> f(x) = 3*x if x<=0. VH> Thus, basically, I would like to write VH> ex MyEx = (x<=0)?3*x:2*x VH> To my best knowledge, boolean expression are not handled in VH> GiNaC, isn’t it ? VH> all the best, VH> Vincent H. -- Docteur Ingénieur de recherche CeMoSiS VH> <http://www.cemosis.fr> - vincent.huber@cemosis.fr Tel: +33 (0)3 VH> 68 8*5 02 06* IRMA - 7, rue René Descartes 67 000 Strasbourg VH> ---------------------------------------------------- VH> Alternatives: VH> ---------------------------------------------------- VH> _______________________________________________ GiNaC-list VH> mailing list GiNaC-list@ginac.de VH> https://www.cebix.net/mailman/listinfo/ginac-list
participants (2)
-
Vincent Huber
-
Vladimir V. Kisil