You can do this in Maxima. There is an external add-on package that can integrate piecewise functions call pw.mac that I wrote. I don't know how to port it to Sage though.
You would do it this way in Maxima. load(pw)$ assume(a>0,b<0,c>0)$ define(p(x), piecewise([-a,(3*b*x^2+3*c)/(6*a*c+2*a^3*b),a],x))$ /* a typical piecewise function */ define(pdf(x), pwdefint(p(p)*p(x-p), p, minf, inf))$ /* this is the convolution */ for i : 1 thru 10 do define(pdf(x), pwdefint(pdf(p)*p(x-p), p, minf, inf))$ /* you can repeat it */ I suppressed the output because it is very messy. Rich -------------------------------------------------- From: "Nasser Abbasi" <n...@12000.org> Sent: Friday, December 25, 2009 11:10 PM To: "sage-support" <sage-support@googlegroups.com> Subject: [sage-support] Re: Symbolic convolution usage Sage > > > On Dec 22, 5:08 pm, Maxim <maxim.courno...@gmail.com> wrote: >> Hi all! >> >> I'm trying to do something which I haven't seen any examples so far : >> symbolic convolution. I know I can use lists or Piecewise defined >> functions to do a convolution, but here my interest is the symbolic >> solution. >> >> To illustrate an example, I would like to make a function that would >> do something like that : >> >> def conv(func1,func2): >> # variable change >> var('t') >> h(tau)=func1(tau) >> x(tau)=func2(-tau+t) >> # proper convolution returns y(t) >> y(t) = integrate(h(tau)*x(tau),tau,-infinity,+infinity) >> return y(t) >> > <SNIP> > > I do not know sage well enough, but can't one in Sage just pass the > independent variable, say "t", as an additional argument to the conv() > function and inside the conv() function, simply write the definition > of the convolution integral? > > This is the convolution of your 2 given functions > > unit_step(t), exp(-0.5*t)*unit_step(t) > > So, in Mathematica, I write the following 4 lines of code: > > f1[t_] := UnitStep[t] > f2[t_] := Exp[-0.5*t]*UnitStep[t] > conv[f1_, f_, t_] := Integrate[ f1[tao]* f2[t - tao], {tao, - > Infinity, Infinity} ] > > (*now do the convolution*) > conv[f1, f2, t] > > Out[11]= (2. - 2./E^(0.5*t))*UnitStep[t] > > The above is y(t). > > Can't the above be translated to Sage? > > --Nasser > > > -- > To post to this group, send email to sage-support@googlegroups.com > To unsubscribe from this group, send email to > sage-support+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org > -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org