Ticket #1773 (assigned defect)

Opened 1 year ago

Last modified 10 months ago

piecewise functions and integration / arithmetic do not play well together

Reported by: was Assigned to: gfurnish (accepted)
Priority: major Milestone: sage-3.4
Component: calculus Keywords:
Cc:

Description

On 1/13/08, Hector Villafuerte <> wrote:
> 
> I defined a piecewise function (specifically, a triangular wave) like this:
> 
> sage: f1(x) = -abs(x) + 1
> sage: f2(x) = abs(x - 2) - 1
> sage: tri_wave = piecewise([ [(-1,1), f1], [(1,3), f2]])
> 
> One can plot it and it looks very nice:
> 
> sage: tri_wave.plot()
> 
> But while calculating this integral I get "ValueError: Value not
> defined outside of domain."
> 
> sage: integrate(tri_wave(x)^2, x, -1, 3)
> 
> Is there a way to integrate piecewise-defined functions?
> As always, thanks for your help,

This is clearly broken.  As a band-aide, you can at least
numerically integrate as follows:

sage: integral_numerical(lambda x: tri_wave(x)^2, -1, 3)
(1.3333333333333333, 1.4765966227514582e-14)

The first output (1.3333...) is the answer, and the second is an error bound.

 -- William

Change History

03/16/2008 01:11:06 PM changed by gfurnish

  • owner changed from was to gfurnish.
  • status changed from new to assigned.