On Thu, 2008-05-29 at 18:58 +0100, Paul wrote:
> is it possible to define a function on the reals, say g(t), that is
> equal to 1 for -1/2 <= t <= 1/2 and 0 otherwise, that integrate knows
> how to handle (for definite
> integrals)?
>
> Trying the obvious with if-then-else doesn't seem to work.
This is "almost" what you want (see note at the end):
(%i16) g(t):= (signum(t+1/2)-signum(t-1/2))/2$
(%i17) g(-0.6);
(%o17) 0
(%i18) g(0.1);
(%o18) 1
(%i19) g(0.6);
(%o19) 0
(%i20) quad_qags(f(t),t,0,3);
(%o20) [.5000000000000001, 5.551115123125784e-16, 273, 0]
(%i21) quad_qags(f(t),t,-3,3);
(%o21) [1.0, 1.110223024625157e-15, 567, 0]
(%i22) quad_qags(f(t),t,3,6);
(%o22) [0.0, 0.0, 21, 0]
The result of the integral is the first element in the list returned by
quad_qags. integrate does not work because it tries to find the
indefinite integral first, to calculate the definite integral. quad_qags
uses an approximate numerical method.
The g(x) above is equal to 1/2 in t=+-1/2, and not 1 as you wanted.
unit_step could be used instead of signum, but quad_qags doesn't work
with unit_step.
Regards,
Jaime