Now having tried it, it looks like the current implementation of Piecewise using "a if test else b" expressions doesn't work with numpy. The test clause returns an array result, which doesn't like being tested as a unit.I've implemented _print_Heaviside like this:def _print_Heaviside(self,expr):a=expr.argsretVal= "((%s)*(%s) + (%s)*(%s) + (%s)*(%s))" % (self._print(S(0)), self._print(Lt(a[0],0)),self._print(div(1,2)), self._print(Eq(a[0],0)),self._print(S(1)), self._print(Gt(a[0],0)))return retValI suspect that those self._print(S(constant)) calls are overkill, but this design seems to work. I'd recommend recrafting Piecewise in a similar way-- though it might be tricky given that Piecewise as documented allows overlapping conditions.
I'm having a different problem with _print_DiracDelta, which I tried this way:def _print_DiracDelta(self,expr):a=expr.argsretVal="((%s)*(%s) + (%s)*(%s))" % (self._print(oo), self._print(Eq(a[0],0)),self._print(S(0)), self._print(Ne(a[0],0)))return retValThe problem being that oo*0 returns nan which, in turn, seizes the rest of my code by the brainstem. Anybody have a clever idea of how to get around this?
I could do some sort of clever indexing to solve the problem in a numpy way, I think, but I'd like to find a general solution.Thanks--Greg
On Monday, March 4, 2013 1:35:11 AM UTC-8, G B wrote:As is probably becoming apparent, I've been busy lambdifying stuff...My latest runtime problem is trying to convolve things with DiracDeltas. The result comes back with a Heaviside function. A quick look through the numpy docs doesn't show a numpy equivalent function for either DiracDelta or Heaviside-- does it makes sense to print these as Piecewise functions?
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
How exactly are you using it? DiracDelta is not really a function. It's a formalism that lets you use integration to get the value of a function at a point. That makes it inherently symbolic. I don't expect there will be an easy numeric version. You'll need to do some preprocessing to get what you really want later on when you (assumedly) integrate. SymPy can likely help you here, as it can symbolically manipulate Dirac deltas.
Sorry if this winds up being a duplicate post-- I thought I sent this earlier, but I haven't seen it come through.How exactly are you using it? DiracDelta is not really a function. It's a formalism that lets you use integration to get the value of a function at a point. That makes it inherently symbolic. I don't expect there will be an easy numeric version. You'll need to do some preprocessing to get what you really want later on when you (assumedly) integrate. SymPy can likely help you here, as it can symbolically manipulate Dirac deltas.I'm using the DiracDelta as one half of a convolution, so you're right, I don't really need a numeric representation. Getting Heaviside to work is enough. The likelihood of sampling the interesting part of the delta is numerically zero anyway. As long as I was doing Heaviside though, DiracDelta seemed like an easy throw-in since it should have followed a similar pattern, but with inf being only a half step from nan, it's treacherous territory.