Comment #4 on issue 2128 by jagermeistermeister: cannot integrate piecewise function numerically
http://code.google.com/p/sympy/issues/detail?id=2128

Oops, found an error already, where can I post a bug report regarding Mateusz's polys11 branch? Should I just put it here?

Just in case:

a = 0.00320838027923401*Piecewise((0, x < -81.7692307692308), (1.33179680150517 - 0.015898400752587*x, x < 2), (Piecewise((0.400000000000000, 2 < x), (0.600000000000000, True)) + Piecewise((0.300000000000000, 123 < x), (0.700000000000000, True)), x <= 123), (2.09276729559748 - 0.0080712788259958*x, x < 382.285714285714), (0, True))

b = -0.0139529089323533*Piecewise((0, x < 1.53846153846154), (-2.925 + 0.845000000000001*x, x < 5), (Piecewise((0.400000000000000, 5 < x), (0.600000000000000, True)) + Piecewise((0.300000000000000, 10 < x), (0.700000000000000, True)), x <= 10), (16.5 - 1.54*x, x < 20.7142857142857), (0, True))

integrate(a.subs(x, x-y) * b.subs(x, y), (y, -oo, oo)) gives an error

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    t = sympy.integrate(a.subs(x, x-y) * b.subs(x, y), (y, -oo, oo))
File "/usr/local/lib/python2.6/dist-packages/sympy/utilities/decorator.py", line 22, in threaded_decorator
    return func(expr, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 545, in integrate
    return integral.doit(deep = False)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 152, in doit
    antideriv = self._eval_integral(function, x)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 283, in _eval_integral
    return f._eval_integral(x)
File "/usr/local/lib/python2.6/dist-packages/sympy/functions/elementary/piecewise.py", line 153, in _eval_integral
    return  Piecewise(*[(integrate(e, x), c) for e, c in self.args])
File "/usr/local/lib/python2.6/dist-packages/sympy/utilities/decorator.py", line 22, in threaded_decorator
    return func(expr, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 545, in integrate
    return integral.doit(deep = False)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 152, in doit
    antideriv = self._eval_integral(function, x)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 283, in _eval_integral
    return f._eval_integral(x)
File "/usr/local/lib/python2.6/dist-packages/sympy/functions/elementary/piecewise.py", line 153, in _eval_integral
    return  Piecewise(*[(integrate(e, x), c) for e, c in self.args])
File "/usr/local/lib/python2.6/dist-packages/sympy/utilities/decorator.py", line 22, in threaded_decorator
    return func(expr, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 545, in integrate
    return integral.doit(deep = False)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 152, in doit
    antideriv = self._eval_integral(function, x)
File "/usr/local/lib/python2.6/dist-packages/sympy/integrals/integrals.py", line 290, in _eval_integral
    poly = f.as_poly(x)
File "/usr/local/lib/python2.6/dist-packages/sympy/core/basic.py", line 651, in as_poly
    poly = Poly(self, *gens, **args)
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/polytools.py", line 98, in __new__
    return cls._from_expr(rep, opt)
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/polytools.py", line 206, in _from_expr
    return cls._from_dict(rep, opt)
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/polytools.py", line 151, in _from_dict
    domain, rep = construct_domain(rep, opt=opt)
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/constructor.py", line 200, in construct_domain
    result = _construct_composite(coeffs, opt)
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/constructor.py", line 148, in _construct_composite
    numer[monom] = ZZ.from_sympy(coeff)
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/domains/pythonintegerring.py", line 34, in from_sympy
    raise CoercionFailed("expected an integer, got %s" % a)
sympy.polys.polyerrors.CoercionFailed: expected an integer, got -6.01396293236025e-7


For the sake of readability, a and b in pretty print look like this:

a:
0.00320838027923401⋅⎧ 0 for x < -81.7692307692308
⎪1.33179680150517 - 0.015898400752587⋅x for x < 2
⎪ ⎧0.4 for 2 < x + ⎧0.3 for 123 < x for x ≤ 123
                    ⎨  ⎨                 ⎨
                    ⎪  ⎩0.6  otherwise   ⎩0.7   otherwise
                    ⎪
⎪2.09276729559748 - 0.0080712788259958⋅x for x < 382.285714285714
⎩ 0 otherwise

b:
-0.0139529089323533⋅⎧ 0 for x < 1.53846153846154
                    ⎪
                    ⎪   -2.925 + 0.845000000000001⋅x            for x < 5
                    ⎪
                    ⎪⎧0.4  for 5 < x + ⎧0.3  for 10 < x         for x ≤ 10
                    ⎨⎨                 ⎨
                    ⎪⎩0.6  otherwise   ⎩0.7  otherwise
                    ⎪
⎪ 16.5 - 1.54⋅x for x < 20.7142857142857
                    ⎪
                    ⎩                0                          otherwise


The problem with integrate(f, (x, -oo, oo)) is gone and works perfectly with Mateusz's branch, though. And fast, too! :)

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to