Say that I have the following function:
f(x) := if x<=0 then 0 else if x<=1 then 1 else -1;
Or any other piecewise defined function.
The function definition seems to work:
(%i9) f(-11);
f(1/2);
f(2);
(%o7) 0
(%o8) 1
(%o9) -1
However integration doesn't evaluate here. It is somehow possible to get the value of the integral here in Maxima? And if not, could it be done numerically in maxima?
load(abs_integrate) to get the abs_integrate package, which enables integrate to handle unit_step. You'll have to write your piecewise function in terms of unit_step. E.g.:
(%i1) load (abs_integrate) $
(%i2) e : unit_step(t) - 2*unit_step(t - 1) $
(%i3) integrate (e, t, a, b);
abs(b) - b - 2 abs(b - 1) - abs(a) + a + 2 abs(a - 1)
(%o3) -----------------------------------------------------
2
For numerical integration, quad_qags (and other quadpack functions) can handle both unit_step and if expressions. quad_qags doesn't need abs_integrate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With