Hi Barton,
I noticed that this works for polynomials as args to signum, abs, or unit_step and returns false otherwise. I think that is really
a bug and it should return the noun form so I added an else clause to it so now for example you get.
(%i1) f:x^2*signum(sin(%pi*x/3));
(%o1) x^2*signum(sin((%pi*x)/3))
(%i2) pwdefint(f,x,-30,30);
(%o2) pwdefint(x^2*signum(sin((%pi*x)/3)),x,-30,30)
Instead of
(%i1) f:x^2*signum(sin(%pi*x/3));
(%o1) x^2*signum(sin((%pi*x)/3))
(%i2) pwdefint(f,x,-30,30);
(%o2) false
I don't know if I will eventuallly make it work for the sin and cos functions too. It is not high on my list. I think I should make
it work for any nonperiodic argument (finite number of roots) if the roots can be found, not just polynomials. My highest priority
is to get indefinite integrals to work. Also I don't want to spend time to support complex solutions to the polynomials since
unit_step and signum don't work right in the complex case.
Try this.
(%i1) domain:complex;
(%o1) complex
(%i2) (x)^2+3=1;
(%o2) x^2+3=1
(%i3) solve([%], [x]);
(%o3) [x=-sqrt(2)*%i,x=sqrt(2)*%i]
(%i4) (x)^2+3=-1;
(%o4) x^2+3=-1
(%i5) solve([%], [x]);
(%o5) [x=-2*%i,x=2*%i]
(%i6) unit_step(x^2+3);
(%o6) 1
(%i6) signum(x^2+3);
(%o6) 1
The last 2 lines are wrong, unit_step(x^2+3) should return unit_step(x^2+3) instead of 1, signum(x^2+3) should return signum(x^2+3)
instead of 1 because in both cases domain is complex. I am not going to worry about it until someone changes the signum and
unit_step behavior for complex domain cases.
Rich
----- Original Message -----
From: "Barton Willis" <willisb at unk.edu>
To: "maxima mailing list" <maxima at math.utexas.edu>
Sent: Tuesday, December 09, 2008 7:05 AM
Subject: integration of signum & friends
Here is one way to evaluate definite integrals of signum and friends;
nothing fancy, just integrate over the subintervals on which signum
and friends do not vanish. Examples:
(%i15) mydefint(abs(x),x,-1,1);
(%o15) 1
(%i17) mydefint(abs(x^2-1) * cos(x),x,-2,3);
(%o17) 6*sin(3)+6*cos(3)+sin(2)+4*cos(2)+8*sin(1)-8*cos(1)
(%i18) mydefint(max(-x,x) + x,x,-9,1);
(%o18) 1
Return a nounform (argument to abs is nonconstant polynomial)
(%i19) mydefint(abs(x-a),x,-1,1);
(%o19) defint(abs(x-a),x,-1,1)
Here, I think the problem is that sign isn't able to simplify the integrand
over each subinterval
(%i20) mydefint(abs(x^2-3),x,-5,42);
(%o20) integrate(abs(x^2-3),x,sqrt(3),42)+integrate(abs(x^2-3),x,-sqrt
(3),sqrt(3))+integrate(abs(x^2-3),x,-5,-sqrt(3))
Maybe somebody would like to fix the bugs in my code, extend it
(indefinite integrals), and make it their own.
Barton
/* This code is lightly tested; I place it in the public domain.
(1) gather the arguments of signum, abs, and unit_step (convert max and
min to abs)
(2) determine where these arguments vanish; call this list of numbers l
(3) sort the list l from low to high
(4) integrate over the intervals formed by the list l
Return a nounform when the arguments to signum & friends aren't constant
coefficient
degree 2 or less polynomials.
*/
load("opsubst");
load("topoly");
dint(e,x, l) := block([],
if emptyp(l) or emptyp(rest(l)) then 0 else
integrate(e,x,first(l), second(l)) + dint(e,x, rest(l)));
mydefint(e,x,lo,hi) := block([l, knots, acc : 0, realonly : true,
prederror : false],
if is(hi < lo)=true then defint(-e,x,hi,lo)
else if is(lo < hi)=true then (
e : ?convert\-from\-max\-min\-to\-abs(e),
l : union(setify(flatten(gatherargs(e, 'signum))), setify(flatten
(gatherargs(e, 'abs))),
setify(flatten(gatherargs(e, 'unit_step)))),
if every(lambda([s], polynomialp(s,[x],'numberp, lambda([s], integerp
(s) and s < 3))), l) then (
knots : [lo, hi],
for lk in l do (
lk : map('rhs, flatten(algsys([lk],[x]))),
for lkk in lk do (
if is(lkk > lo and lkk < hi) then knots : cons(lkk, knots))),
dint(e,x, sort(knots, lambda([a,b], is(compare(a,b) = "<")))))
else funmake('defint,[e,x,lo,hi]))
else funmake('defint,[e,x,lo,hi]));
_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima