On Thursday 29 May 2008 21:58, Paul wrote:
> I'm new to Maxima so forgive my ignorance, but 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.
matchdeclare (t,true,[a,b], lambda([x],constantp(x) and imagpart(x)=0))$
spint (a,b) := (
if a > b then
-spint(b,a)
else (
if a < -1/2 then a : -1/2,
if b > 1/2 then b : 1/2,
b-a
)
)$
tellsimp(square_pulse(t), (if t<-1/2 or t > 1/2 then 0 else 1))$
tellsimp('integrate(square_pulse(t),t,a,b), spint(a,b))$
integrate(square_pulse(t),t,-1/5,4) => 7/10
For more complicated integrals, use quad_qags:
quad_qags(sin(t)*square_pulse(t),t,-1/5,4) => .1024840159508691
--
Alexey Beshenov <al at beshenov.ru>
http://beshenov.ru/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20080529/18694a3c/attachment.pgp